How to use Pivot function for group range in oracle SQL
Hi,
Good Morning !!!
I need to show the data in the below format. There is 2 columns 1 is State and another one 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 below query but unable to use the range on pivot function . Please help on this.
(select (SELECT SHORT_DESCRIPTION
FROM CODE_VALUES
WHERE CODE_TYPE_CODE = ad.STATE_TYPE_IND_CODE
AND VALUE = ad.STATE_CODE
) STATE,
nr.rate
FROM neutrals n,
contacts c,
addresses ad,
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' )
user8564931 wrote:
This solutions is useful and Thanks for your reply.
How can i get the Min value and Max value for each row ?
State <100 100-199 200-299 300-399 400-499 500-599 600-699 700-799 800-899 900-999 >=1000 Total Min Max
IL 0 0 1 5 1 5 40 1 1 40 0 53 $10 $2,500
IN 0 0 0 0 0 0 1 49 49 1 0 3 $70 $1,500This?
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
t1 AS
( 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)
SELECT STATE,
"<100",
"100-199",
"200-299",
"300-399",
"400-499",
"500-599",
"600-699",
"700-799",
"800-899",
"900-999",
">=1000",
"<100"
+ "100-199"
+ "200-299"
+ "300-399"
+ "400-499"
+ "500-599"
+ "600-699"
+ "700-799"
+ "800-899"
+ "900-999"
+ ">=1000"
total,
least("<100",
"100-199",
"200-299",
"300-399",
"400-499",
"500-599",
"600-699",
"700-799",
"800-899",
"900-999",
">=1000") min_val,
greatest("<100",
"100-199",
"200-299",
"300-399",
"400-499",
"500-599",
"600-699",
"700-799",
"800-899",
"900-999",
">=1000") max_val
FROM t1
/
Similar Messages
-
How to use destination function for javascript
Hi,
I used javascript:var a = window.open('OA.jsp?page=/oracle/apps/cdar/admin/brandupload/webui/SupportPG&retainAM=Y&OARF=printable', 'a','height=500,width=900,menubar=yes,toolbar=yes,location=yes'); a.focus(); in destination URL property, it can work to popup another window.
But I want to setup a Oracle function for this javascript, and use Destination FUNC property on the button to popup window. But it can not work after I setup a SSWA jsp function with WEB HTML.
Could some one help this?
Thanks,
EileenEileen,
How are you adding the OA function ? I have also tried destination url property but not the destination function.Probably you should do sth like this :
In ProcessRequest :-
<OABean> <var name> = (<OABean>)webBean.findChildRecursive("<Bean Id>");
<var name>.setOnClick("javascript:window.open ('OA.jsp?OAFunc=<funcName>','new','height=550,width=850,status=yes,scrollbars=yes,toolbar=no,menubar=no,location=no' );
OABean is the bean on click of which the page should open like a hyperlink or sth like that.
Hope this helps. -
How to view execution history for any date in oracle SQL developer tool ?
hi, i want to view some executed queries(2 months before) in oracle SQL Developer. if i press F8 it shows execution history for only last 30 days. is there any option(query) or something to view execution history for specific date ? i want to see some queries, which is executed before 2 months in my oracle SQL developer tool. Pls help me out.
sb92075 wrote:
943838 wrote:
hi, i want to view some executed queries(2 months before) in oracle SQL Developer. if i press F8 it shows execution history for only last 30 days. is there any option(query) or something to view execution history for specific date ? i want to see some queries, which is executed before 2 months in my oracle SQL developer tool. Pls help me out.it will never occurWhy not? Are you a member of the product team that develops SQL Developer?
To the OP, there is a forum for SQL Developer
SQL Developer
And there's also a sticky on the forum for product enhancement requests
"Feature Requests, Extensions and General Collateral "
Cheers, -
How to use evaluate function for sql server function
Hi Team,
We have imported a column(date dtat type) from SQL server cube . By default it imported as varchar,. We have three option in physical layer for this column(Varchar,Intiger,unknown)
So we want to convert this column into date.can we use evaluate or there is any option to do that.?Hi,
I am not sure your requirement. But how pass evaluate function obiee?
syntax:- EVAULATE('your db function(%1,%2)', parameter list)
here %1 and %2 are the no.of parameters (columns or may constant values) to be passed for the db-function
if you have 3 parameters then you need to use %3 also.. means the columns to be passed.
following exapmples are for ORACLE db,
ex1: EVALUATE('upper(%1)', 'satya ranki reddy') gives the result as -> SATYA RANKI REDDY
ex2: EVALUATE('upper(%1)', 'Markets.Region') here Markets.Region is column.
you also can call the user-defined functions through evaulate
EVALUATE('functioname(%1,%2), column1, column2)
the above function has 2 parameters to be inputted
Hope this help's
Thanks
Satya -
How to use cursor function for nested xml
Hi,
i have a query for XMLQuery like
select * from bills where bill_id=????
it results in something like
<bills>
<bill>
<city>london</city>
<amount>44</amount>
</bill>
<bill>
<city>london</city>
<amount>988</amount>
</bill>
<bill>
<city>new york</city> <amount>59</amount> </bill>
</bills>
but i want xml output to be sorted for city names adding one more level location like
<bills>
<location city="london">
<bill>
<amount>44</amount>
</bill>
<bill>
<amount>988</amount> </bill>
</location>
<location city="new york">
<bill>
<amount>59</amount> </bill>
</location>
</bills>
it should be possible to iterate through the same table to gather informaton with the help of cursor function, but never used CURSOR before.
any idea?sreese wrote:
p_desig works as a comma delimited string without the NVL function, that's not the issue.
It IS the issue .. you need to provide a SAMPLE so we can see what you're doing ..
How are you "passing it in" ?
option A:
procedure ( in_var in VARCHAR2 )
AS
and nvl(sn.c_attribute1,'x@#$%') in nvl(in_var,'x@#$%')
option B:
and nvl(sn.c_attribute1,'x@#$%') in nvl(&1,'x@#$%')
.. or some other method? -
Satellite U200-122: How to use Pivot function on external Monitor?
I have a Satellite U200-122, would like to use the external monitor in pivbot function.
But I do not find where I can have the display rotate, so that it will be displayed in portrait format on the external monitor and accept resolution 1024x1280.
Any ideas?
Graphic driver: Intel Chipset 945GM express
Thanks
IsabelThax for the tipp, but:
That is exactly my problem: the intel graphics acceklerator DOES NOT offer any rotate functionality! I wonder why because I have read in many forums that it should have, I know it can be seen on the right part of the intel graphics accelerator window, but nothing is there.
So i wonder, if in the U200 there is possibly a different graphic driver or management sofwtare, which just does not support this? Could it be that a graphic driver does not offer pivot???
Shortcuts do not work either.
Btw: when i put the laptop on a kensington workstation, then the kensington graphic manager -display -link - is used, and then with many workarounds i do get the monitor to show pivot in necessary reolution. but i want a to use a pivot monitor also at home without dockingstation... -
How to use debatching function for SyncRead FileAdapter?
Dear all,
We are using Inbound Opague fileadapter to read the filename, then invoke the syncRead Fileadpter to get the content. My question is how to set batching for syncRead Fileadapter? I didn't find this option in wizard.
Platform is SOA Suite 11.1.1.3.
Thank you.
Regards,
TonyAgain as I said I never implemented. You can try having a invoke activity in while loop. I believe batch of 10 means it will read 10 records and every time in while loop you should increment BatchIndex.
You can raise a Oracle Support ticket if required. -
How to use CHANGEDOCU functions for audit trail?
Hi,
I have a report screen that requires audit trails on the changes made to the data dic fields on the screen.
Which CHANGEDOCU functions should I use for audit trail? And where should I implement the functions? In the 'save' subrountine that I create?
Any samples? Thanks.Hi Kian,
You should wtite the change docu functions in the "SAVE" subroutine. The following changedocu functions should be used. I am attaching an example if it below.
CALL FUNCTION 'CHANGEDOCUMENT_OPEN'
EXPORTING
OBJECTCLASS = 'ZSCHEMES'
OBJECTID = OBJECTID
PLANNED_CHANGE_NUMBER = PLANNED_CHANGE_NUMBER
PLANNED_OR_REAL_CHANGES = PLANNED_OR_REAL_CHANGES
EXCEPTIONS
SEQUENCE_INVALID = 1
OTHERS = 2.
CASE SY-SUBRC.
WHEN 0. "OK.
WHEN 1. MESSAGE A600 WITH 'SEQUENCE INVALID'.
WHEN 2. MESSAGE A600 WITH 'OPEN ERROR'.
ENDCASE.
IF UPD_ZIRD_P_SCHEMES NE SPACE.
CALL FUNCTION 'CHANGEDOCUMENT_SINGLE_CASE'
EXPORTING
TABLENAME = 'ZIRD_P_SCHEMES'
WORKAREA_OLD = O_ZIRD_P_SCHEMES
WORKAREA_NEW = N_ZIRD_P_SCHEMES
CHANGE_INDICATOR = UPD_ZIRD_P_SCHEMES
DOCU_DELETE = 'X'
EXCEPTIONS
NAMETAB_ERROR = 1
OPEN_MISSING = 2
POSITION_INSERT_FAILED = 3
OTHERS = 4.
CASE SY-SUBRC.
WHEN 0. "OK.
WHEN 1. MESSAGE A600 WITH 'NAMETAB-ERROR'.
WHEN 2. MESSAGE A600 WITH 'OPEN MISSING'.
WHEN 3. MESSAGE A600 WITH 'INSERT ERROR'.
WHEN 4. MESSAGE A600 WITH 'SINGLE ERROR'.
ENDCASE.
ENDIF.
CALL FUNCTION 'CHANGEDOCUMENT_CLOSE'
EXPORTING
OBJECTCLASS = 'ZSCHEMES'
OBJECTID = OBJECTID
DATE_OF_CHANGE = UDATE
TIME_OF_CHANGE = UTIME
TCODE = TCODE
USERNAME = USERNAME
OBJECT_CHANGE_INDICATOR = OBJECT_CHANGE_INDICATOR
NO_CHANGE_POINTERS = NO_CHANGE_POINTERS
EXCEPTIONS
HEADER_INSERT_FAILED = 1
OBJECT_INVALID = 2
OPEN_MISSING = 3
NO_POSITION_INSERTED = 4
OTHERS = 5.
CASE SY-SUBRC.
WHEN 0. "OK.
WHEN 1. MESSAGE A600 WITH 'INSERT HEADER FAILED'.
WHEN 2. MESSAGE A600 WITH 'OBJECT INVALID'.
WHEN 3. MESSAGE A600 WITH 'OPEN MISSING'.
WHEN 4. MESSAGE A600 WITH 'NO_POSITION_INSERTED'.
do not abort, if positions are not inserted!!!
WHEN 5. MESSAGE A600 WITH 'CLOSE ERROR'.
ENDCASE.
Reward me points if you found it useful.
Thanks
Abhishek Raj. -
How to use custom function for formatting the Line Chart Axes?
Hi...
I'm using a Line chart who's y axis value range from 0 to 50000. This is a number which it gets from it's dataProvider. I want to format this and show it as
$50,000
$40,000
$30,000
$20,000
$10,000
$0
instead of
50000
40000
30000
20000
10000
0
Here's my linechart code:
<mx:LineChart id="revTimeLineChart"
width="100%" height="100%"
showDataTips="true" >
<mx:horizontalAxis>
<mx:CategoryAxis id="lcCatAxis" categoryField="name"/>
</mx:horizontalAxis>
<mx:series>
<mx:LineSeries id="ls" yField="revenue" displayName="Revenue" showDataEffect="{slideIn}"/> (yField is what I want to format....)
</mx:series>
</mx:LineChart>
Can you please let me know how can this be achieved?
Cheers!
DeepakHi,
You could do something like this,
http://www.codersrevolution.com/index.cfm/2008/10/14/Flex-Charting-Format-your-X-and-Y-Axi s
hope it helps!
Regards ,
Bhavika -
How to use bluetooth function for the Mega player(522BT)
Hello all!!!!!
Pls ,help me!
I am from Myanmar.I can't use Mega player(522BT)for PC to the bluetooth function of this device.
That is ,we can only use the phone to this device.
I want to know. Pls,help me.
With Regards,
Thwe Thwe(Myanmar)Hi,
You could do something like this,
http://www.codersrevolution.com/index.cfm/2008/10/14/Flex-Charting-Format-your-X-and-Y-Axi s
hope it helps!
Regards ,
Bhavika -
How to use LIKE function with a parameter in Oracle REPORT builder??
how could i use parameter inside a LIKE function in Oracle reports builder?
it works in SQL plus, but not in report builder!!
Example:
select code,desc from item_master where desc
like '%&give_desc%'; ---works in SQL
like '%:give_desc%' ---doesn't work in report builder!!Hi Renil,
You will need to use the wildcard character (%) and the concatenation character (||) to join to your user parameter.
i.e. like '%'||:give_desc||'%'
Regards,
John -
How to implement password policy for a software in oracle (sql) forms & reports 6i ?
Hi all , I have to implement password policy for an already existing software which was created 2 to 3 years before.
What exactly i want to do is I must alert the user every month to change his/her password. I have no idea about it.
Can anyone help me how to start with it? Or can you provide me the links where i can learn & implement in the software?
Oracle Forms & Reports Builder 6i.
Oracle9i Enterprise Edition Release 9.2.0.1.0 - Production.
Thank You.You can try this:
Establishing Security Policies
Using database policy, you can force user to change password with Oracle forms 6i.
Regards -
How to use ABS function when using BWA connection
Hi Experts,
We are using InfoSpace on top of BWA
Could you kindly let me know how to use ABS functionality for InfoSpace
Because we want to use formula: (A-B) / Abs(B), we cannot get ABS (B)
Would you kindly help on this?
Best regards
Alex yangrepost
-
How to use data function using characterstics variable for calculation on
how to use data function using characterstics variable for calculation on attribute as key figure
Hi Gayatri
Did you not see my answer for CASE because CASE does indeed offer the use of the BETWEEN clause, but DECODE does not. Let me give you a little synopsis of DECODE.
In its most simple form it takes 4 values and looks like this: DECODE(A, B, C, D)
This essentially means, IF A = B THEN C ELSE D
The trick to solving BETWEEN in a DECODE is to work out algoriths where A = B. Because we don't know how many values are between 00 and 99, although I could guess there were 100 we could of course have 100 parts in the DECODE but that would be awful. How about if we look at it another way and say this:
IF PART_NUMBER < 'SDK00' THEN pay_amount
ELSE IF PART_NUMBER > 'SDK99' THEN pay_AMOUNT
ELSE pay_amount + 100
This statement only had 2 hard coded values, but how to make DECODE work with less than? Easy, we use the LEAST function. The LEAST function takes 2 values and returns the one with the lowest value. So I use LEAST(PART_NUMBER, 'SDK00') then whenever the PART_NUMBER is lower than SDK00 it will be true. A similar situation exists for the opposite function GREATEST. Putting all of this together then, you can do this:
DECODE(PART_NUMBER, GREATEST(PART_NUMBER, 'SDK00'), DECODE(PART_NUMBER, LEAST(PART_NUMBER, 'SDK99'), PAY_AMOUNT * 100, PAY_AMOUNT), PAY_AMOUNT)
In English this can be read as follows:
IF the PART_NUMBER is greater than or equal to SDK00 and the PART_NUMBER is less than or equal to SDK99 THEN PAY_AMOUNT x 100 ELSE 0
Best wishes
Michael -
How to use java api for function activity in embed oracle workflow?
because i can't install standalone oracle workflow successfully.
pls tell me how to use java api for function activity in embed oracle workflow?
are there some patch or pulg-in package?
ths a lot...........The Java Function Activity Agent is not certified for Oracle Workflow embedded in Oracle Applications. Installing standalone workflow should be a lot easier than what you have found, although it looks like you did hit a Pentium 4 issue with the Oracle Universal Installer. I suggest you contact Oracle Support or Oracle Consulting for assistance.
because i can't install standalone oracle workflow successfully.
pls tell me how to use java api for function activity in embed oracle workflow?
are there some patch or pulg-in package?
ths a lot...........
Maybe you are looking for
-
ITunes Player: Error message when syncing with iTunes
What is going on with iTunes, When I plug one end of the sync cord into my 5th Generation iPod Touch and the other end in the computers usb port, it starts to load like it's gonna sync but then it's saying The iPod "Becky's iPod" could not be synced
-
I have 4 computers in my network. 3 desktops and 1 laptop. 2 desktops are wired to the LAN and 1 laptop and 1 desktop are connected wirelessly. Every computer including my windows desktop hooked up wirelessy to the LAN can play itunes content off my
-
Extracting Purchase order details
Hai All, I am workng on a report in which I have to display the purchase order and GRN details for a given Purchase Requisition number. If the PR has 5 line items and PO is made only for 2 line items, then the purchase order details for on
-
Update fiel "parentId" table OCLG
When trying to update a table "OCLG" parentId field, returns me the following error: "Field parentId is read-only". How to do the update in this field? The field still has no value and want to include this value in this column. Here's how I'm doing:
-
SRM-MDM prices multiplikated with 10
Hello, we are running SRM-MDM 3.0 I'd like to run MDM with Services. All works great but the pricing is a little bit strange. I fill the price in my item into the field Hss Hierarchy Price with 99,00 Euro, Base price Quantity 1, and all other fields