Pivot / without pivot function-example
HelloCan someone explain to me the differece between pivot and pivot function.
Concerning
SA
Hello
Please find below the queries for your reference. Function pivot is introduced by from 11 g. Before that, we can solve the problems with the 'breaks', 'decode' functions.
But the pivot and unpivot functions are very flexible to Oracle11g to get the line to columns and vice versa outputs.
Oracle 10g
***********
Select the task,
sum (case when deptno = 30
then the sal
Another null
end) dept30
sum (case when deptno = 10
then the sal
Another null
end) dept10
sum (case when deptno = 20
then the sal
Another null
end) dept20
sum (case when deptno = 40
then the sal
Another null
end) dept40
Sum (SAL) Total_Sal
WCP
Working Group
Oracle 11g
**********
Select the task, dept_30, dept_10, dept_20, total_sal
de)
Select work,
DEPTNO,
SAL,
Sum (SAL) on total_sal (work partition)
WCP
)
pivot)
Sum (SAL)
to deptno in)
30 as dept_30,
10 as dept_10,
20 as dept_20));
I hope that you understand the above examples...!
KPR
Tags: Database
Similar Questions
-
Query type pivot without aggregation function. Transposition of the
Hi experts,
Oracle 11g.
I have a table (see the sample code to reproduce), which has a date, a group and this group (determined in another query) County. I need a query of type pivot, but without aggregate functions. It's just for a view reports. I can't understand it. Thanks for your help.
Using SQL but I must return the following:CREATE TABLE temp_task AS SELECT TO_DATE ('15-NOV-2012') validation_date, 'GROUP 1' AS group_number, 42 AS monthly_count FROM DUAL UNION ALL SELECT TO_DATE ('14-DEC-2012') validation_date, 'GROUP 1' AS group_number, 33 AS monthly_count FROM DUAL UNION ALL SELECT TO_DATE ('15-NOV-2012') validation_date, 'GROUP 2' AS group_number, 10 AS monthly_count FROM DUAL UNION ALL SELECT TO_DATE ('14-DEC-2012') validation_date, 'GROUP 2' AS group_number, 32 AS monthly_count FROM DUAL UNION ALL SELECT TO_DATE ('15-NOV-2012') validation_date, 'GROUP 3' AS group_number, 7 AS monthly_count FROM DUAL UNION ALL SELECT TO_DATE ('14-DEC-2012') validation_date, 'GROUP 3' AS group_number, 9 AS monthly_count FROM DUAL;
VALIDATION_DATE | GROUP 1 | GROUP 2 | GROUP 3
15/11/2012. 42. 10. 7
14/12/2012 | 33. 32. 9Hello
You should always use an aggregate function while rotating.
Even if you have really no aggregation, in other words, when what you see in the table, it's what you will get in the result set, you will have to use an aggregate function. Is there is only a value contrinuting for each cell, then you can use the MIN or MAX. It will not matter which; Since there is only 1 value, this value will be the greater of 1, and it will be also the lowest. For NUMBER of columns, you can also use SUM or AVG.SELECT * FROM temp_task PIVOT ( MIN (monthly_count) FOR group_number IN ( 'GROUP 1' , 'GROUP 2' , 'GROUP 3' ) ) ORDER BY validation_date ;
Output:
VALIDATION_ 'GROUP 1' 'GROUP 2' 'GROUP 3' ----------- ---------- ---------- ---------- 15-Nov-2012 42 10 7 14-Dec-2012 33 32 9
Looks like you're doing real aggregation somewhere, to get monthly_count. It would be perhaps easier and more efficient to do the swivel at this time. What is the big picture here? Post some sample data, as it is before you calculate monthly_count and desired outcomes from these data (if it is different from what you have already posted), then we'll see if we can not aggregte it and pivot it at the same time.
-
help in the application without using the pivot function
Hi gurus,
Can you please help write the query without using the PIVOT function.
Thanks in advance!...WITH indata AS (SELECT 1 sn, '123:456,789,323:456,213,344,345:5454' x from dual UNION ALL SELECT 2, 'abcd:fgrfr,rfrf,rfred,tg:tg,tg:ophhh,op,vdfgbh:poijn' x from dual), instr AS (SELECT a.SN, rownum RN, B.column_value || CASE WHEN B.column_value NOT LIKE '%:%' THEN ':' END column_value FROM indata a, TABLE(CAST(multiset (SELECT trim(SUBSTR(x, (CASE LEVEL WHEN 1 THEN 1 ELSE instr(x, ',', 1, LEVEL - 1) + 1 END), (CASE instr(x, ',', 1, LEVEL) WHEN 0 then 4000 ELSE instr(x, ',', 1, LEVEL) - 1 - (CASE LEVEL WHEN 1 THEN 0 ELSE instr(x, ',', 1, level - 1) END) END))) FROM dual CONNECT BY level <= LENGTH(x) - LENGTH(REPLACE(x, ',', '')) + 1) AS sys.odcivarchar2list)) b) SELECT col1_val2, col1_val1, col2_val2, col2_val1, systimestamp FROM (select SN, ROW_NUMBER() over(partition by SN order by RN) RN, SUBSTR(column_value, INSTR(column_value, ':') + 1) VAL1, substr(column_value, 1, instr(column_value, ':') - 1) val2 FROM instr ) PIVOT(MAX(VAL1) VAL1, MAX(VAL2) VAL2 FOR SN IN(1 as col1,2 as col2));
Any help would be appreciated.user590978 wrote:
Can you please help write the query without using the PIVOT function.
with indata as ( select 1 sn,'123:456,789,323:456,213,344,345:5454' x from dual union all select 2, 'abcd:fgrfr,rfrf,rfred,tg:tg,tg:ophhh,op,vdfgbh:poijn' x from dual ), t1 as ( select x from indata where sn = 1 ), t2 as ( select x from indata where sn = 2 ), t3 as ( select level lvl, substr( x, instr(',' || x,',',1,level), instr(x || ',',',',1,level) - instr(',' || x,',',1,level) ) col1 from t1 connect by level <= length(x) - length(translate(x,'A,','A')) + 1 ), t4 as ( select level lvl, substr( x, instr(',' || x,',',1,level), instr(x || ',',',',1,level) - instr(',' || x,',',1,level) ) col2 from t2 connect by level <= length(x) - length(translate(x,'A,','A')) + 1 ), t5 as ( select lvl, substr(col1,1,instr(col1 || ':',':') - 1) col1_val1, substr(col1,instr(col1 || ':',':') + 1) col1_val2 from t3 ), t6 as ( select lvl, substr(col2,1,instr(col2 || ':',':') - 1) col2_val1, substr(col2,instr(col2 || ':',':') + 1) col2_val2 from t4 ) select col1_val1, col1_val2, col2_val1, col2_val2, systimestamp from t5 full join t6 on ( t6.lvl = t5.lvl ) order by coalesce(t5.lvl,t6.lvl) / COL1_VAL1 COL1_VAL2 COL2_VAL1 COL2_VAL2 SYSTIMESTAMP ---------- ---------- ---------- ---------- ------------------------------------- 123 456 abcd fgrfr 23-OCT-12 11.50.12.015000 AM -04:00 789 rfrf 23-OCT-12 11.50.12.015000 AM -04:00 323 456 rfred 23-OCT-12 11.50.12.015000 AM -04:00 213 tg tg 23-OCT-12 11.50.12.015000 AM -04:00 344 tg ophhh 23-OCT-12 11.50.12.015000 AM -04:00 345 5454 op 23-OCT-12 11.50.12.015000 AM -04:00 vdfgbh poijn 23-OCT-12 11.50.12.015000 AM -04:00 7 rows selected. SQL>
SY.
-
How to use the Pivot function for range group in oracle SQL
Hello
Hello!!!
I need to display the data in the format below. There are 2 columns 1 is State and another is rate.
State < 100 100-199, 200-299 300-399 400-499, 500-599 600-699 700-799 800-899 900-999 > = 1000 Total
AK 1 2 0 4 1 4 4 35 35 4 1 25
AL 0 0 2 27 10 17 35 2 2 35 0 103
AR 0 0 1 0 0 2 2 13 13 2 0 6
AZ 0 1 2 14 2 14 13 3 3 13 0 57
CA 0 0 1 6 2 7 3 4 4 3 0 34
Developed the sub query but unable to use the beach on the pivot function. Please help on this.
(select (SELECT short_description
OF CODE_VALUES
WHERE CODE_TYPE_CODE = ad. STATE_TYPE_IND_CODE
AND VALUE = ad. STATE_CODE
) STATE,
Nr.rate
N-NEUTRAL
c contacts,
announcement of addresses,
xref_contacts_addresses xca,
neutral_rates nr
where n.contact_id = c.contact_id
and n.address_id = ad.address_id
and xca.address_id = ad.address_id
and xca.contact_id = c.contact_id
and nr.contact_id = n.contact_id
and nr.rate_frequency = 'HOUR')Like this
with t as ( select 'AL' state, 12 value from dual union all select 'AL' state, 67 value from dual union all select 'AL' state, 23 value from dual union all select 'AL' state, 12 value from dual union all select 'AL' state, 12 value from dual union all select 'AL' state, 78 value from dual union all select 'AL' state, 34 value from dual union all select 'AL' state, 4 value from dual union all select 'AL' state, 12 value from dual union all select 'AL' state, 15 value from dual union all select 'AZ' state, 6 value from dual union all select 'AZ' state, 123 value from dual union all select 'AZ' state, 123 value from dual union all select 'MA' state, 23 value from dual union all select 'MA' state, 120 value from dual union all select 'MA' state, 456 value from dual union all select 'MA' state, 11 value from dual union all select 'MA' state, 24 value from dual union all select 'MA' state, 34 value from dual union all select 'MA' state, 87 value from dual union all select 'MA' state, 23 value from dual union all select 'MA' state, 234 value from dual union all select 'MA' state, 789 value from dual union all select 'MH' state, 54321 value from dual ) -- End of test data select state, nvl(count(decode(value, 0, 0)), 0) "<100", nvl(count(decode(value, 1, 1)), 0) "100-199", nvl(count(decode(value, 2, 2)), 0) "200-299", nvl(count(decode(value, 3, 3)), 0) "300-399", nvl(count(decode(value, 4, 4)), 0) "400-499", nvl(count(decode(value, 5, 5)), 0) "500-599", nvl(count(decode(value, 6, 6)), 0) "600-699", nvl(count(decode(value, 7, 7)), 0) "700-799", nvl(count(decode(value, 8, 8)), 0) "800-899", nvl(count(decode(value, 9, 9)), 0) "900-999", nvl(count(decode(value, 10, 10)), 0) ">=1000" from ( select state, case when value < 100 then 0 when value between 100 and 199 then 1 when value between 200 and 299 then 2 when value between 300 and 399 then 3 when value between 400 and 499 then 4 when value between 500 and 599 then 5 when value between 600 and 699 then 6 when value between 700 and 799 then 7 when value between 800 and 899 then 8 when value between 900 and 999 then 9 when value >= 1000 then 10 end value from t ) group by state
-
Satellite U920T - 10G - touch screen without any function
Hello together,
I have been using the nice nice feature now for a few weeks and start to have trouble with him.
I have the problem that randomly touch screen without any function, I can touch the screen
but I want to, but without any reaction.It starts just besides the requests or anything before, I just browsing in the web site and a second to another.
If I restart the PC, everything works normally again, I still using the drivers that have been pre-installed and have no changes for the drivers so far.
Any suggestions, what could cause this problem?
Kind regards
Hello
In my opinion, a process that controls the touch screen hangs or does not answer more and as a result, you can not touch works.
Recommend reinstalling the driver of Toshiba + Toshiba UE driver page system.
If this is not enough to try the system recovery and test the device with factory settings. -
be combined with for example explain.
NandhaKumar.S wrote:
be combined with for example explain.Welcome to the forum, since you're new here you may not know... This isn't a replacement for google.
http://www.google.ca/#hl=en&sclient=psy-ab&q=oracle+cumulative+function+example&oq=oracle+cumulative+function+example&aq=f&aqi=q-w1&aql=&gs_l=hp.3..33i21.395.6578.0.6675.44.25.5.8.9.6.970.6670.0j10j9j0j3j1j1.24.0...0.0.CGGyqhf6GLc&pbx=1&bav=on.2,or.r_gc.r_pw.r_qf.,cf.osb&fp=cd620d727463c7b6&biw=1338&bih=909Please try actually using some research and independent thinking before asking a question here.
See you soon,.
-
Pivot table result without aggregate function
Hi all
We have the following two tables:
SQL > select * from class;
CLASS_ID COURSES
---------- ----------
1 1
2 1
3 1
2 2
3 2
5 2
6 selected lines.
SQL > select * of course.
COURSE_ID
----------
1
2
The customer needs the output in the following format:
class class class class
1 1 2 3
2 2 3 5
I considered using the operator pivot tables however they require the use of an aggregate function, but there is no aggregation only required in the result here - we demand that the output as would a PivotTable?
Try this.
WITH class(CLASS_ID,COURSE) AS)
1.1 DOUBLE UNION ALL SELECT
SELECT 2.1 DUAL UNION ALL
SELECT 3.1 FROM DUAL UNION ALL
SELECT 2.2 DUAL UNION ALL
3.2 DUAL UNION ALL SELECT
SELECT DOUBLE 5.2)
SELECT * FROM)
SELECT THE COURSE
CLASS_ID,
ROW_NUMBER () OVER(PARTITION BY COURSE ORDER BY COURSE) RN
CLASS)
PIVOT (MAX (CLASS_ID) for (RN) IN (1 as CLASS1, 2 AS CLASS2, CLASS3 AS 3));
OUTPUT:
CLASS CLASS1 CLASS2 CLASS3
-------- ---------- ---------- ----------
1 1 2 3
2 2 3 5
-
no aggregation of pivot function
Oracle Database 11 g Enterprise Edition Release 11.2.0.3.0 - 64 bit Production
PL/SQL Release 11.2.0.3.0 - Production
CORE Production 11.2.0.3.0
AMT for Linux: Version 11.2.0.3.0 - Production
NLSRTL Version 11.2.0.3.0 - Production
Hi, thank you very much in advance.
I want to combine two lines into a single line, group by (area_code, team, office_code, supervisorID) - if the collector ID (IS_DESKCALL = 'Y') and collectorID(IS_DESKCALL='N') in the same line. As it is not an aggregation function, so I can't use function pivot in 11g?
/ * Formatted on 05/11/2014 19:34:09 (v5.139.911.3011 PS5) * /.
WITH T AS (SELECT '31012' office_code,)
AREA_code '00003',.
1 TEAM,
SUPERVISOR_ID '201204135',
' NO IS_DESKCALL.
'201205000' COLLECTOR_ID
OF THE DOUBLE
UNION
SELECT '31012' office_code,
AREA_code '00003',.
1 TEAM,
SUPERVISOR_ID '201204135',
'Y' IS_DESKCALL,.
'201205555' COLLECTOR_ID
OF THE DOUBLE
UNION
SELECT '31012' office_code,
AREA_code '00003',.
1 TEAM,
SUPERVISOR_ID '201204888',
' NO IS_DESKCALL.
'201205000' COLLECTOR_ID
OF THE DOUBLE
UNION
SELECT '31012' office_code,
AREA_code '00003',.
1 TEAM,
SUPERVISOR_ID '201204888',
'Y' IS_DESKCALL,.
'201205555' COLLECTOR_ID
OF THE DOUBLE
UNION
SELECT '77777' office_code,
AREA_code '00003',.
1 TEAM,
SUPERVISOR_ID '201204999',
' NO IS_DESKCALL.
'201205023' COLLECTOR_ID
OF THE DOUBLE
UNION
SELECT '77777' office_code,
AREA_code '00003',.
1 TEAM,
SUPERVISOR_ID '201204999',
'Y' IS_DESKCALL,.
'201205444' COLLECTOR_ID
THE DOUBLE)
SELECT *.
T
The result should be:
office_code area_code team supervisorID collectorID(IS_DESKCALL='Y') collectorID(IS_DESKCALL='N')
31012 00003 1 201204135 201205555 201205000
31012 00003 1 201204888 201205555 201205000
77777 00003 1 201204999 201205444 201205023
As it is not an aggregation function, so I can't use function pivot in 11g?
You can use MIN (or MAX):
select * from t pivot ( min(collector_id) for is_deskcall in ( 'Y' as collector_id_y , 'N' as collector_id_n ) ) ;
-
Hello experts.
I have data similar to what follows below
create table t1 ( id number(30), description varchar(4000) ); insert into t1 values (1, 'zone'); insert into t1 values (2, 'small'); create table t2 ( id number(30), place varchar(4000), info varchar(4000) ); insert into t2 values (1, 'USA', 'Class U'); insert into t2 values (1, 'Mexico', 'Class M'); insert into t2 values (2, 'Germany', 'Class G');
I need help with something similar to what follows below without using any analytic function
Description of the ID info Place
1 box USA class U
Mexico 1 M class
2 small Germany class G
Any help is appreciated. Thank you
Hello
user13328581 wrote:
... I use an older version of oracle. Oracle 7.
Normally, your developers are older than your software.
You should be able to do what you want with a self-join on t2; a copy (d) should be displayed, and the other copy (c) contains all related values you need for comparison.
SELECT t2d.id
DECODE (t2d.place
MAX (t2c.place)
t1.description
) AS description
t2d.place
t2d.info
FROM t1
, t2 t2d - display
t2 t2c - compare
WHERE t1.id = t2d.id
AND t2d.id = t2c.id
GROUP BY t1.description
t2d.id
t2d.place
t2d.info
ORDER BY t2d.id
t2d.place DESC
;
Output:
ID DESCRIPTION PLACE INFO
---------- -------------------- -------------------- --------------------
1 box USA class U
Mexico 1 M class
2 small Germany class G
I've tested this in Oracle 11, but it should work in Oracle 7.
If this isn't the case, you may need to create a view.
-
Hello
I want to create a table of contents in my E-Learning-project because the automatically generated TOC of Adobe Captivate 7 includes all the features I need to check for example chapters which are the groups in the film strip.
I use master slides in my project.
The table of contents, I need must be designed and programmed as follows:1 intro / title slides
9 chapters
The progress of the work - 3 status - all chapters should be moved by symbols in the table of contents
Symbol 1: chapter has not yet begun (just an empty box)
Side 2: chapter is work in progress (a square with a green triangle inside)
Side 3: chapter is finished that means that all of the slides in this chapter are read (the square is filled with a green square)All the chapters and Points to the table of contents must be clickable (links) maybe with a mouse over effect (change in colour of mouse) and should start to the first slide of this chapter.
The chapter which is open must be written in bold with one blue color, others who are not open to be written in the normal font with a black color
I think it's a little complex, but solutionable.
I think I need to create three symbols of the buttons form, advanced actions that tend to fade and fade out named symbols.
Is there someone who can describe the process of creation? Where should I place all the functions, actions and so on? On the slide master?
Thank you for the answers!
The only thing I can say about it is that I build it in Flash, so it could be dynamic and reusable.
If you take the time to build a PC inside it only works for one project. Certainly you would have a base to work from, but for a another edition project wouldn't be fun.
If you need HTML5, I think it would be much more difficult to build a dynamic table of contents.
-
Text search without wildcards - for example 'Howe' but not 'how '.
A lot of old messages to go without finding common words such as 'how' and «and' instead of simply 'Howard' or «candles»
From your description, I suspect you use the global search, which I agree is a bit lame.
There is an older search tool, accessed by ctrl + shift + f, which allows a more precise search. And because it is based on the same set of tools such as Message filters, additional such as FiltaQuilla modules and search for term / Gmail UI that enhance the capabilities of filtering are also available in your research.
The main disadvantage with ctrl + shift + f search is that it is based on records; She looks in the current folder only. One way to work around this is to use a saved, search where you have so much stronger search/filtering rules and the ability to select which folders to search in.
-
no need
Johnalaska said
I'm sorry, I'm new and thought since it was a forum for Thunderbird that refer to v38.0.1 and no function to hide [normally under the icon drop-down TB] would be obvious.
But I'm wrong.
Here is a screenshot of TB menu icon dropdown with only Quit showing.
Sorry, I don't have a Mac. Someone else who should be able to answer your question.
-
Use VirtualBench API without LabVIEW. Example: Python, dll, etc.
Hello
I would like to know if there is a way to use the API VirtualBench without LabVIEW?
As the use of python or something.
Thank you
We just released version 1.1 of VirtualBench that adds a C API and a bunch of other features, see http://forums.ni.com/t5/VirtualBench/Announcing-free-firmware-update-version-1-1-adds-SPI-and-I2C/td.... With whom you could use VirtualBench in your programming language of choice if you write the appropriate links.
-
Leaking handles when calling C API Via "Call library function" (example attached)
Hi all
Thank you for any assistance you can give. I am a pretty good C programmer and a mediocre programmer LabVIEW so keep that in mind. I created a VI and C simple API to illustrate the issue (all sources included, built with Visual Studio 2005)
I drove a DLL of the C API with LabVIEW as you can probably guess. There is a delicate part of the C API which requires some pointer math to work. This is the part that is leaking handles (seen in the Task Manager, below. Handles over 2 million and growing). The leak is only seen in LabVIEW and not when you call my API directly from C code (the code for the example C example is also attached)
)
The VI that illustrates the problem is quite simple.
LabVIEW moves of the buffer returned by "card Seq Blk Rd.vi' autour and causing 'Card Seq find Next429Ex.vi' to fail. It's my first clue that something is wrong - I think not that my buffer must move each time. I have to actually do some pointer math in my real API to fix this, but did not bother with this example. The question is the same regardless of the fix - up.
The attached zip contains my example VI, and C for the API Source code and an example of C using the API (which does not leak handles).
I'm sure I'm not enter a relatively simple concept LabVIEW memory management here, but still a mediocre time so be nice.
Regards and thanks in advance.
Brad
-
How to solve 12 Code in the device without help function Manager?
Recently noticed the triangle/point of yellow exclamation mark in device for my graphics (Intel 82865 G) Manager. Turns out to be a Code 12 problem. I tried the path to solve the problems, but I still get this error message: "Microsoft Help and Support Center has encountered a problem and needs to close. We are sorry for the inconvenience. "Anyway I can diagnose/fix this without the troubleshooting tool, or what I need to fix the troubleshooting tool itself?
Hello
I suggest you check out the link to download graphics drivers:
Maybe you are looking for
-
If you are a reseller and you sell one of these phones, please advise your customers that Mobile data is set on YOU! including homelessness and substance! And the first time you go to the store of Google play, it will use ALL your data to download an
-
Save the LV of many plots to Excel chart
I have a LV graphic with ten plots on it. You will just need to save it in Excel. Many attempts and problems. Is it still possible without sending all data to Excel table, then a link to the chart in the same workbook?
-
no backup error: (0 x 80070570)
My laptop Acer Aspire 4520 with windows vista is this error whenever I try to do a backup system, someone knows how to fix this? -Quest P.S. I had just taken my laptop fixed from a virus. PPS ok, maybe it was a backup file
-
BlackBerry Smartphones 9790 My calendar information is missing
I sync my blackberry with my calendar outlook (gmail account) and I noticed yesterday that everything had disappeared from the blackberry calendar. I tried to re-synchronization (from the computer to the device) and it seems to work but nothing is a
-
Cannot use video when Jabber is in command mode of fixed phone
Scenario: The use of Jabber 9.2.1 to control a Cisco 7945. I compose a Cisco SX20 by DN video unit, and call connect in audio mode only. Jabber usually allows for me to start the video after the call connects in audio mode only, but in this scenario