need help on the clause type
I have a temp table as below
LOC X CNT
20 20 C
80 20 N
60 30 C
40 30 N
100 40 N
the rule is for each column of the LOC, there are 2 records of C, N and sum (NTC) must be = 100. If there is no value for C for a LOC (LOC = 40) then the value of the CNT corresponding to C should appear as null or 0 if the value of N is > 0.
I need a model clause to do this, see below,
LOC X CNT
20 20 C
80 20 N
60 30 C
40 30 N
100 40 N
0 TO 40 C
Why why why? I am not able to understand the model clause. How did you learn model clause?
Tags: Database
Similar Questions
-
I have a query as below
Select empno, deptno, sum (sal) on tot_sal (partition deptno) from scott.emp;
will give the result like this
EMPNO DEPTNO TOT_SAL
---------- ---------- ----------
7934 10 8750
7782 10 8750
7839 10 8750
7902 20 10875
7876 20 10875
7566 20 10875
7369 20 10875
7788 20 10875
8 selected lines.
but as you can see the total sal and deptno repeats, what I want is wise dept total salary as shown below
EMPNO DEPTNO TOT_SAL
---------- ---------- ----------
7934
7782
7839
Total for deptno 10 = 8750
7902
7876
7566
7369
7788
Total for deptno = 20 10875
I want to use the type clause and get the above result970426 wrote:
Karthik repliedPublished by: 970426 on January 24, 2013 04:13
You are not yet able to determine good projection on your own?
select nvl(to_char(empno),'Total for deptno '||deptno||': '||sal) empno from emp model partition by (deptno) dimension by (row_number() over( partition by deptno order by empno) rn) measures (sal, empno) rules( sal[0]=sum(sal) [any] ) order by deptno, empno
Katrick solution uses my idea of deptno [0]. It has a useless subquery, a useless measure, two unnecessary rules.
Please don't give any of my points.
Jiust learn a thing about it.
Introduction to thinking on your own. -
SQL query help needed in the Clause type
Hello
I'm currently learning Clause type. How can I write in the clause type to get the result below:
I have a table like this
DEPTNO ENAME
------- ------
20 SMITH
CELINE 10
BOND 20
ALLEN 30
WARD 30
20 JONES
30 MARTIN
30 BLAKE
10 CLARK
SCOTT 20
10 KING
30 TURNER
20 ADAMS
30 JAMES
20 FORD
10 MILLER
I want the output should look like this
DEPTNO ENAME
------ -----
CELINE 10, CLARK, KING, MILLER
20 JONES, ADAMS, BOND, FORD, SCOTT, SMITH
30 MARTIN, JAMES BLAKE, WARD, TURNER, ALLEN
Hear is the script I am currently working on.
with emp_group as
(
Select 20 deptno, ename 'SMITH' Union double all the
choose 10, 'CÉLINE' from dual union all
Select 20, "BOND" of all the double union
Select 30, 'ALLEN' from dual union all
Select 30, 'WARD' of all the double union
Select 20, "JONES' from dual union all
Select 30, 'MARTIN' from dual union all
Select 30, "BLAKE" from dual union all
choose 10, 'CLARK' from dual union all
Select 20, 'SCOTT' from dual union all
choose 10, 'KING' of the dual union all
Select 30, 'TURNER' from dual union all
Select 20, 'ADAMS' from dual union all
Select 30, 'JAMES' of the dual union all
Select 20, 'FORD' Union double all the
choose 10, 'MILLER' from dual
)
Select
DEPTNO
A1
of emp_group
model
ignore the nav
partition (deptno)
dimension (ROW_NUMBER() over (PARTITION BY deptno ORDER BY ename DESC) rn)
measures (ename, LPAD(' ', 100) A1)
rules)
A1 [rn > 0] = ename [cv ()],
A1 [0] = ename [cv ()]
)
order by deptno
;
your help is very appreciated.
Thank you in advance.
Try this.
Select
*
Of
(
with emp_group as
(
Select 20 deptno, ename 'SMITH' Union double all the
choose 10, 'CÉLINE' from dual union all
Select 20, "BOND" of all the double union
Select 30, 'ALLEN' from dual union all
Select 30, 'WARD' of all the double union
Select 20, "JONES' from dual union all
Select 30, 'MARTIN' from dual union all
Select 30, "BLAKE" from dual union all
choose 10, 'CLARK' from dual union all
Select 20, 'SCOTT' from dual union all
choose 10, 'KING' of the dual union all
Select 30, 'TURNER' from dual union all
Select 20, 'ADAMS' from dual union all
Select 30, 'JAMES' of the dual union all
Select 20, 'FORD' Union double all the
choose 10, 'MILLER' from dual
)
Select
DEPTNO
names
rn
of emp_group
model
ignore the nav
partition (deptno)
dimension of)
ROW_NUMBER() over (PARTITION BY deptno ORDER BY ename) rn
)
measures (ename, cast (null as names of varchar2 (40)))
rules
(
names [any] order by desc = ename [cv ()] rn | «, » || names [cv () + 1]
)
order by deptno
)
where rn = 1
Best regards, Andrei
-
How to use the clause type conditionally create new lines
This question is just for learning - no object other than to start real world to create versions of some queries known to learn how to measure the performance of the MODEL clause clause of the MODEL versions.
The question is: How can you write a STANDARD clause that pivots (updates) ONLY the lines that actually need to rotate and do NOT change the lines that have no value and cannot be rotated.
I found a good site that has about two dozen example articles on different pieces. This first link is the beginning of the series.
SQL features tutorials - Clause TYPE
http://www.sqlsnippets.com/en/topic-11663.html
This link is to a clause of FAQ of BluShadow MODEL version "how to convert rows to columns."
Line - MODEL method string
http://www.sqlsnippets.com/en/topic-11987.html
The solution to this link uses this line of source:
POSITION KEY VAL
--- ---------- ----------
R08 0 v1, v2, v3,.
and this result set:
POSITION KEY VAL
--- ---------- ----------
R08 1 v1
R08 2 v2
R08 3 v3
The reason why it produces that result set is this clause of the statement of MODEL
RETURN THE UPDATED LINES
If you comment on this article, you will see that the original lines are all in position 0. This means that the solution reproduced EACH SOURCE LINE even if there is only one item in the list of values.
Thus, even a line source with a single value (for example, the r01 'a') will be updated and updated this line is returned.
For a large number of data sources with only a few lines that actually need to rotate it would be a great performance of infringement.
This is the sample data source
with t as (button 1, 'a' value 'abc' col2, col3 'def' of the double
Select Union all 2, 'b', 'ghi', 'jkl' from dual
Union all select 3, 'c, d, e, 'mno', 'pqr' from dual.
Union all select 4, 'f', 'stu', 'vwx' from dual
)
Select the key, value, col2, col3
tKEY, VALUE, COL2, COL3
1, a, abc, def
2, b, GHI, jkl
3, "c, d, e, mno, pqr.
4, f, stu, vwxLines 1, 2 and 4 only have a value of (a, b, c respectively.
Only line 3 must rotate. It contains "c, d, e" and which must become 3 lines in the result set
Value of the key, col2 col3
1 an abc def
2B ghi jkl
3 c mno, pqr
3 d mno, pqr
3 e mno, pqr
4 f stu vwxThe nut of the problem is that if the clause 'RETURN UPDATED ROWS' is used, then the lines 1, 2 and 4 must be updated in order to be returned in the result set. And if this clause is NOT used, then line 3 must be updated by 'c', d, e 'c' and two new product lines: one line for a ' and one for 'e '.
How can you do this with the TYPE clause without the help of the clause "Return LINES UPDATE"? I don't have a solution to sample showing what I tried because I can't understand what it takes to even try.
I have a solution that uses "RETURN UPDATED ROWS" but I want to compare this performance to the exercise, when this clause is NOT used.
We ask BluShadow to add the solution of MODEL clause to this FAQ with other similar solutions.
Like this?
SQL > with t as
() 2
3 select the 1 key, 'a' val, 'abc' col2, col3 'def' of the double
Select 4 Union all 2, 'b', 'ghi', 'jkl' from dual
5 union all select 3, 'c, d, e, 'mno', 'pqr' from dual.
Select 6 Union all the 4 'f', 'stu', 'vwx' from dual
7)
8. Select the key
9, key_1
10, val
11, regexp_substr (val, ' [^,] +', 1, key_1) val_new
12, col2
13, col3
14 t
model 15
16 partition by (key)
dimension (1 key_1) 17
18 measures (val, col2, col3, (length (val) - length (replace (val, ",")) + 1) as len)
19 rules
(20)
21 val [for 1 to increment of len key_1 [1] 1] = val [1]
22, col2 [for 1 to increment of len key_1 [1] 1] = col2 [1]
23, col3 [for 1 to increment of len key_1 [1] 1] = col3 [1]
24)
25 order
26 by key
27, key_1;KEY KEY_1 VAL VAL_N NECK NECK
---------- ---------- ----- ----- --- ---
1 1 has an abc def
2 b 1 b ghi jkl
3 1 c, d, e c mno pqr
3 2 c, d, e d mno pqr
3 3 c, d, e e mno pqr
4 1 f f stu vwx6 selected lines.
-
Need help with the button mute on my helmet XL-3000 of Microsoft Chat, please!
Hi all! Hope everyone is having a good TGIF! If you use my helmet even, I need help understanding the region button mute in the middle of the rope. The red light is on or off? I suppose that if I hit the curve button with the microphone on this subject, and the red light, I'm turn off my mike?
I did some tests with others on the phone calls. Sometimes, some other hear me, sometimes they do not have. BUT I NEVER HEAR THEM! FOR MY WORK, IT IS IMPERATIVE THAT I MAKE CALLS TO OTHERS! HELP PLZ! Thank you very much and have a great wkend!
Hello
Please follow the links below to troubleshoot the computer.
Method 1
Connect one microphone, music player or other audio device to your computer
Method 2
Step 1
Troubleshooting: headsets
Step 2
Open the troubleshooting of Audio recording
Method 3
How to adjust the microphone volume
a. click Start, type mmsys.cpl in the search box and press ENTER.
b. in the sound dialog box, click the recording tab.
c. click Microphone, and then click Properties.
Note Make sure that the work appears under Microphone. If the job does not appear, click Microphone, and then click on set as default.
d. the Microphone Properties dialog box, click the custom tab.
e. select or clear the box amp Microphone.
f. click the levels tab.
g. set the volume to the desired level, and then click OK.
h. click OK to close the sound dialog box.How to adjust the setting of the voicea. start the game.
b. connect to LIVE (the Guide).
c. click personal settings.
d. click on voice.
e. make sure that the recording volume level indicator records at a bar when you talk.
f. click done.If you are still facing problems then, I would say that you contact support for Microsoft hardware for more direct intervention.
I hope this helps.
-
Hi all
I need help license the following environment:
1 400 VDIs.
2. associated VDI servers.
3-8 non - VDI associated servers.
This environment runs on 6 dual CPU servers.
Concerning
For this, but all these already include vSphere, ESX and vCenter licenses.
Advanced also include VSAN.
Advanced horizon is available as simultaneous user and username, so if you can choose what type of license would be the most suitable for you, in most cases, the concurrency model is best suited.
So say you have 400 concurrent users, you need 400 advanced Horizon permits and are then all included vSphere licenses.
Linjo
-
I'm on Acrobat 10 for mac and I need help with the distribution of shape feature. Is there a way to change the registration e-mail download addressed to the? Currently all forms I create and then distribute may only be subjected to my email account... I appreciate any help!
Do not use the feature distribute the form. Instead of this, just put up a button "submit" and configure it to send email using any email address you want. Just add a button and set the action of the mouse upward on "Submit a form" and use a type mailto URL and specify that you want to send the full PDF. Then activate the reader of the document: where "Advanced/extended features in Adobe Reader" is located in Acrobat XI?
If you really want to use distribute the form for some reason, change the e-mail address in your preferences: Edit > Preferences > identity > Email address
-
Hi all
I read some documents oracle and and some examples
I understand that this model is used to create the table multidimensional and for the prediction of the future.
but I am not able to write the query using the type clause.
Please someone help me to understand the clause type base.
I want everything clause type to start from scratch.
Please guide me.Links: http://rwijk.blogspot.in/2007/10/sql-model-clause-tutorial-part-one.html.
http://rwijk.blogspot.in/2007/10/SQL-model-clause-tutorial-part-two.htmlThere is a post over here in the OTN forum. Please do a search.
Concerning
BijuEdited by: biju2012 1 Sep 2012 16:02
(The link for part 2 is provided)Published by: biju2012 on Sep 2, 2012 02:45
-
My mac mini (mid-2010) speed/performance is very slow - think of it as a result of letting my kids do "whatever" about it in recent years. Need help, consolidate the files, software updates, etc. in order to improve the speed and performance. You will also need to get data out of old PowerBook G4.
< object edited by host >
We are users like you. Search locally by using something like Yelp or similar
or read a few links which may be relevant on this forum about the slow mac mini
-
Need help with the installation of an adapter of graphics Super Palit GeForce 9500GT - 512 MB - DDR2 SDRAM in a M2N68 motherboard (narra6). Should I disable the onboard graphics in the bios? When the card is installed, no VGA work outs and the PC does not start. Checked and recontroler implementation of the card in the PCI slot. PC is a desktop HP G5200uk PC. Windows 7 operating system.
Hello
The link below is a guige to install a video card in your Pc. In particular, it seems that you will have to perhaps specify the location of the new card in the bios and save this change before you install the new card - see step 4 in the guide on the link below. If your new card fits into the PCI Express x 16 slot, you will need to define PCI Express in the bios and save the changes.
http://support.HP.com/us-en/document/c01700855
Kind regards
DP - K
-
Satellite Pro A300-15V, I need help in the Organization of my startup list
Hello everyone!
I need help in the Organization of my startup list:
(Why should Toshiba button support I this program if my laptop doesn't have multimedia keys? OR maybe this program for something else?)
ItSecMng (although I have disabled the Bluetooth Manager to run when starting from this point still remains in the startup)
Agent of filtering of Audio Conexant high definition (what is this program? Do I really need to start?)
TOSHIBA Power Saver
Toshiba Flash Cards
RAID event monitorSo, my friends. Could you give a valuable suggestion whether or not it is prudent to disable startup above entries? I want to speed up my laptop at the highest possible level.
Thanks a lot for your time!
Kind regards
Osman.My laptop:
Toshiba Satellite Pro A300-15V (PSAJ5E) => NOT have multimedia keys except the FN keys.
> Toshiba Button support (why should I this program if my laptop doesn't have multimedia keys? OR maybe this program for something else?)
You can disable it. If your mobile phone does not support the multimedia buttons then this tool is useless.> ItSecMng (although I have disabled the Bluetooth Manager to run when starting from this point still remains in the startup)
I don't know what would make this process, but you can disable this in msconfig-> tab start Mr. If it would take in the future, then you could turn it on again.> Agent of filtering the Conexant high definition Audio (what is this program? Do I really need to start?)
I think that this is necessary. It could improve your audio> Toshiba Power Saver
This is important. It s an additional saving of Toshiba option for Win 7> Toshiba Flash Cards
This tool controls the FN keys.> RAID Event Monitor
Hmm so you don t have two hard disks, then you can try to disable it too. -
I need help to the new photo of my photos from iphoto on El Capitan. Any help would be appreciated.
To migrate your iPhoto library to Photos for Mac, drag it in the Photos icon in the Dock. Photos will read the iPhoto library and create a new library of pictures of him.
Is your photo library in iPhoto on an external drive? The migration will work that if the external hard drive Mac OS extended (journaled) file system. If the library is on a disk with a different file system, Ministry of the environment of the library of a correctly formatted disk.
-
I need help with the program of Photos on my macbook pro
I use a Macbook Pro with OS of Yosemite. I really need help with the Photo program. I never really got the hang of IPhoto and now that it's a new program, I'm really confused. Where can I go to learn this without waiting for the next workshop in a local store?
Hi, I'm fighting to open same mine, making a new software update
-
Need help with the launching track pack for forza code 4
Bought new Forza 4 and the lancer Track Pack code does not work, how do I get a code that is generated in the form I've already paid for it. Rank of loads of numbers and sent 10 s of emails but cant seem to get help.
This is the help I get when the cat to an Ambassador xbox on xbox.com
Terry wrote:Need help with the launching track pack for forza code 4The Xbox Ambassador says:Location of Ambassador of the community...The Xbox Ambassador says:Location of Ambassador of the community...The Xbox Ambassador says:Your question will be answered by an Ambassador of the Xbox. You have been connected to the Ambassador as a user Xbox [3]The Xbox Ambassador says:HelloTerry wrote:HelloThe Xbox Ambassador says:HeyTerry wrote:just to be on the phone to xbox live support and was told to come hereThe Xbox Ambassador says:ok\The Xbox Ambassador says:What is your problem?Terry wrote:I bought the 4 for forza ansd 360 new sealed Christmas...Terry wrote:has got 2 codes that accompanies the game but the pack track code does not workThe Xbox Ambassador says:Wow goodTerry wrote:whenever I put in the code it says code redeemedThe Xbox Ambassador says:I think the code is used. You must return to the retailerTerry wrote:I tried to, but since I already opened the case they will not acceptThe Xbox Ambassador says:Oh. No,Terry wrote:the code had been used or defective as I am the only person who has touched the game once opened, tried to enter the code when it is openThe Xbox Ambassador says:Maybe it was auto bought?Terry wrote:so, how do I get another code generated track Pack if defective?The Xbox Ambassador says:I do not know.Terry wrote:bought the game new, so I get the track packThe Xbox Ambassador says:Oh. It's bad.The Xbox Ambassador says:I think that if you Exchange 1 code it will buy itTerry wrote:car pack code worked, starter pack did not workThe Xbox Ambassador says:Oh.The Xbox Ambassador says:It's a badThe Xbox Ambassador says:BTW you have an evolution of the tests?Terry wrote:Yes, I want to? but more anxious to get a code object generated for this packThe Xbox Ambassador says:Hey if I help can u give me this game too?Terry wrote:?????????????????Terry wrote:So is it possible to get a code for that time?The Xbox Ambassador says:HeyThe Xbox Ambassador says:Yes.The Xbox Ambassador says:you need to contact themThe Xbox Ambassador says:and tell them that the code is used.Terry wrote:I was told to come here? where can I go to get the code?Hi Terryg76,
· What version of the operating system is installed on the computer?
I suggest you to contact the game manufacturer for more help and information.
-
I need help for the upgrade of my current system.
I need help for the upgrade of my current system.
I have SBS 2008 with (Exch 2007, SQL 2005, Sharepoint, backupexec 2010 for sbs) licenses.
I want to make the larger environment using the following:
(1) apply Virtualization
(2) apply to the failover process (clustering)
"(3) the environment must support adding server terminal server, ERP server, exchange server, domain controller, backup manager.
Storage 4) that supports Raid (1 and 5)
UTM excellent 6) that supports (SSL VPN, VPN Global)
suitable backup solution 7)
(8) good antivirus for clients
my questions:
(1) can you provide me with a good design for this environment
(2) should I choose what operating system:
Microsoft datacenter or company
I know datacenter provide us the unlimited VM but needs per processor license
so if I have two Grouped servers I want to buy 4 licenses
and just 4 VMs per company license... to say that we have two servers and maintain 8 vms so wat happened if 1 goes down... How can I migrate the 4 virtual machines on the server failed to another server group... ? should I buy enterprise license?
(3) if I get the SAN storage for data... How can I save this storage... should I get another SAN?
(4) how can I upgrade SBS stad single server (windows standrad) without losing the licenses as Exch 2007, SQL 2005, sharepoint.is it a must to buy an edition full std server or there is a way to upgrade (license wise, I mean)?
(5) what about win2k8 license for VM:
lets say we have physical that has windows license so that enough to have windows for VM or should I buy windows for VM licenses?
(6) can I use backExec license for SBS with windows 2008 standard
(7) who better to virtualization AMD or INTEL
(8) hyper V or VMware?
(9) what of Microsoft data protection Manager... is this good?
(10) what virtual machine manager? What are the benefites keys
Thanks in advance
Hello AnasAI,
You can find the Server forums on TechNet support, please create a new post at the following link:
http://social.technet.Microsoft.com/forums/en/category/WindowsServer/
Maybe you are looking for
-
معرف ولكن لا يمكن فتح الهاتف
-
Impossible to find support for Toshiba 32VL733
Where is the support for toshiba 32vl733? This model doesn t exist on your site. When you put a new firmware? To solve the problem as: youtube dosen t work either, put a new firmware for supported more formats like the mkv, blu ray with subtitles...
-
Satellite P300 - bandwidth Expresscard
According to this article: [http://en.wikipedia.org/wiki/ExpressCard], expresscard may be: -in mode USB2 480Mbs only-in mode PCIExpress to 2.5 Gbps How can I find out if my Satellite P300 is in USB2 mode / PCIExpress?Y at - it a tool of diagnosis her
-
How can I stop the Safari fix my spelling?
Safari continues to change my e-mail address of an English word. I want that it STOP!
-
'open with' program Pop Up on every Application I try to use it, but does not work
When I try to install anything, open it with the Application comes up and no matter what I do, it does allow Me to install games, or Windows 7