Query output for group by
Hi !
Can someone help ?
What I am looking for is, those days in the first query which do not return any rows should be displayed with a 0. I have all the days available in that table. Ie. 13/14/15th it should display as 0 instead of skipping it
SQL> select trunc(logtimestamp),count(*)
from SOACOE_LOGGER_SUMMARY
where
ERRORTYPE is not null
group by trunc(logtimestamp)
order by trunc(logtimestamp); 2 3 4 5 6
TRUNC(LOGTI COUNT(*)
05-MAR-2009 2
06-MAR-2009 13
07-MAR-2009 6
08-MAR-2009 1
09-MAR-2009 3
10-MAR-2009 3
12-MAR-2009 1
17-MAR-2009 36
18-MAR-2009 28
9 rows selected.
SQL> select distinct trunc(logtimestamp)
from SOACOE_LOGGER_SUMMARY
order by trunc(logtimestamp); 2 3
TRUNC(LOGTI
05-MAR-2009
06-MAR-2009
07-MAR-2009
08-MAR-2009
09-MAR-2009
10-MAR-2009
11-MAR-2009
12-MAR-2009
13-MAR-2009
14-MAR-2009
15-MAR-2009
TRUNC(LOGTI
16-MAR-2009
17-MAR-2009
18-MAR-2009
19-MAR-2009
15 rows selected.Thanks
G
SQL> WITH soacoe_logger_summary AS
2 (
3 SELECT DATE '2009-3-5' AS logtimestamp, 1 AS errortype
4 FROM DUAL
5 UNION ALL
6 SELECT DATE '2009-3-6', 1
7 FROM DUAL
8 UNION ALL
9 SELECT DATE '2009-3-7', 1
10 FROM DUAL
11 UNION ALL
12 SELECT DATE '2009-3-8', 1
13 FROM DUAL
14 UNION ALL
15 SELECT DATE '2009-3-9', 1
16 FROM DUAL
17 UNION ALL
18 SELECT DATE '2009-3-10', 1
19 FROM DUAL
20 UNION ALL
21 SELECT DATE '2009-3-12', 1
22 FROM DUAL
23 UNION ALL
24 SELECT DATE '2009-3-17', 1
25 FROM DUAL
26 UNION ALL
27 SELECT DATE '2009-3-18', 1
28 FROM DUAL)
29 SELECT d, COUNT(logtimestamp)
30 FROM soacoe_logger_summary,
31 (SELECT mindate + LEVEL - 1 AS d
32 FROM (SELECT MIN(logtimestamp) AS mindate, MAX(logtimestamp) AS maxdate
33 FROM soacoe_logger_summary)
34 CONNECT BY LEVEL <= maxdate - mindate + 1)
35 WHERE ERRORTYPE(+) IS NOT NULL AND d = TRUNC(logtimestamp(+))
36 GROUP BY d
37 ORDER BY d;
D COUNT(LOGTIMESTAMP)
05.03.09 1
06.03.09 1
07.03.09 1
08.03.09 1
09.03.09 1
10.03.09 1
11.03.09 0
12.03.09 1
13.03.09 0
14.03.09 0
15.03.09 0
16.03.09 0
17.03.09 1
18.03.09 1
Similar Messages
-
Dear Consultants,
I want to take a print out from Group Deliveries I did the output determination, created the output condition record and created the group delivery when am trying to take the print out system giving the message that
No output has been selected for printing
, system not considering the condition record. when ever i want to print the group delivery, manuallay I am enter the information because of the above problem.
some one can help to fixup this.
Thanks and Regards,
MHCheck in the following IMG path
Logistics Execution => Shipping => Basic Shipping Functions => Output Control => Output Determination => Maintain Output Determination for Groups => Maintain Output Determination Procedure.
Here ensure that you have maintained the required condition type there. Next click "Assign Output Determination Procedures" and ensure that you have assigned the required output procedure for your Group Type
thanks
G. Lakshmipathi -
AD Query String for Group Membership
Hi
I have found that inbound mail to distributions groups (Ex07) are not being delivered. Running a trace, I am seeing they are failing on LDAP match. I tracked it down to the qroup query not working. We are using the default query. Running a test, it fails. I think that is the problem. I can mail the group internally just fine.
Anyone have a good query string that will check for distribution groups? Below is the query being used. Thanks for the help.
(&(memberOf={g})(proxyAddresses=smtp:{a}))Can you go to the LDAP section and provide all the fields that are relevant?
I'll need the LDAP configuration fields (minus the password of course) and what you're using for the LDAP Accept.
Well I opened a ticket with support, and it appears that I have them stumped. From what they tell me it isn't the ldap group query that is failing, but rather the ldap accept query failing.
Sending to the group does work internally so It looks like ldap is good with the the proxy address, but ironport is failing on the query.
Snippit from trace:
Envelope Recipient Processing
Envelope Recipient: [email protected]
LDAP Accept Lookup: Result: failed
Default Domain Processing: No Change
Domain Map Processing: No Change
Recipient Access Table Processing: Behavior: ACCEPT Matched On: [email protected]
Alias Expansion: No Change -
Force a column in the query output for FYPD when no data exists
Hi ,
I have a requirement, data available in the cube
<b>FYPD-----Costcenter---- Emp#----StartPD---EndPd--
Amt</b>
2007001-----123456 789---2007004-2008012--
$10
In the variable input screen FYPD range is entered ex: 2007001 - 200704
expected report output;
<b>costcenter--Emp# -StartPD---EndPdAmt- 2007001-- 2007002 -
2007003----
2007004 (Columns KF's)</b>
23456--78920070042008012$10000--
1.
The 0 and 1s are calculated based on Start& End Pd. If STARTPD <= FYPD<= ENDPD
Then output = 1 else 0.
Problems:
1. How to force columns for 2007002 to 200704 when there is no data in the cube for those periods?
2.If somehow we are able to force the columns how to use the column header in the formula to calculate 1 or 0?
Any idea?????If you add some kind of calculation behind your KF that is based on a field that exists for all records it should be fine. This can be a formula variable based on an characteristic attribute like (mat weight/mat weight).
If you're saying you want a 0 to show up when there are no records in the cube for the characteristics in question then it may be more difficult.
Please clarify -
Removing Leading zeros from query output.
Hello Experts,
Is it possible to remove leading zeros from the query output for a particular column?
I have a characteristics 'Reference Document' which has values like '000001386'. The users just need '1386' to be displayed and have asked us to remove the leading zeros.
Is there something that can be done for this at a query level? I can't modify the underlying InfoProvider because this requirement is just for one set of users, the other users need the document nmber in the original format.
Thanks
ArvindHi,
you can use ALPHA conversion option in the definition of that particular characteristic.
Try this code in a routine.,in query designer;
data a(9) value '000001386'.
SHIFT a LEFT DELETING LEADING '0'.
write:/ a.
Output will be : 1386
Or use this method also
data a(9) value '000001386'.
Call function 'CONVERSION_EXIT_ALPHA_OUTPUT'
Exporting
input = a
Importing
output = a.
write a.
output:
1386
Regards
CSM Reddy -
Output varies for group by & where Clause
Below are the two statements which i am comapring .
1) for this i get a output as it displays 0 because there are no rows matched to this criteria .
select count(No) from T1 where No = 3"
1
0
1 record(s) selected.
2) Same way i am looking to get output for this statement .If value exists it gives the count if not it should return 0.
select count(*) from T1 GROUP BY No HAVING No = 3"
1
0 record(s) selected.
Can someone suggest thisuser587133 wrote:
Below are the two statements which i am comapring .
1) for this i get a output as it displays 0 because there are no rows matched to this criteria .
select count(No) from T1 where No = 3"
1
0
1 record(s) selected.
2) Same way i am looking to get output for this statement .If value exists it gives the count if not it should return 0.
select count(*) from T1 GROUP BY No HAVING No = 3"
1
0 record(s) selected.
Can someone suggest thisIn the second query the having clause is applied after the count, so the count is being done and then any rows matching the having clause are returned. As there are no rows matching the having clause the result is that no rows are returned. The count is being done, but you are filtering out those rows from the result. -
Query need for transpose data output
Dear All,
I have a query regarding transpose output.
for ex. I created one table employee in database
create table emp(emp_no number,dept_id number(10));
it is having data like....
emp_no dept_id
101 10
102 20
103 10
104 10
105 20
so I want the output in transpose format like
dept_id emp_no1 emp_no2 emp_no3
10 101 103 104
20 102 105
can anybody suggest me any query for the above output.
Thanks...
Prashant....select dept_id
, max (decode (emp_no, 101, emp_no))
, max (decode (emp_no, 102, emp_no))
, max (decode (emp_no, 103, emp_no))
, max (decode (emp_no, 104, emp_no))
, max (decode (emp_no, 105, emp_no))
from test
group by dept_idas in
SQL> with test as
2 (
3 select 101 emp_no, 10 dept_id from dual union all
4 select 102 emp_no, 20 dept_id from dual union all
5 select 103 emp_no, 10 dept_id from dual union all
6 select 104 emp_no, 10 dept_id from dual union all
7 select 105 emp_no, 20 dept_id from dual
8 )
9 select dept_id
10 , max (decode (emp_no, 101, emp_no)) emp1
11 , max (decode (emp_no, 102, emp_no)) emp2
12 , max (decode (emp_no, 103, emp_no)) emp3
13 , max (decode (emp_no, 104, emp_no)) emp4
14 , max (decode (emp_no, 105, emp_no)) emp5
15 from test
16 group by dept_id
17 ;
DEPT_ID EMP1 EMP2 EMP3 EMP4 EMP5
20 102 105
10 101 103 104 -
Change layout of Adhoc query output list for Custom infotype
Hi All,
The fields in the Infoset query output on a custom infotype are aligned with the fields u2018payment typeu2019 and u2018amountu2019 appearing repeatedly(in columns) as declared in the Infotype and the output will be a long horizontal list.
Instead, the requirement is that the output list should show vertically so that If I choose u2018Payment Typeu2019 and u2018Amountu2019 as output fields, it will show a long vertical list as in the case of a standard infotype (IT0008).
Also, this way enables user to use Payment Type as a selection criteria so as to just pulling the needed payment type. When we use IT0008 in the infoset it works fine but in custom IT it does not work.
Any pointers/suggestions on how we can achieve this would be helpful.Hi yu liang,
You can find vendor list having Vendor No. & without showing total liability for every vendor.
after executing the report,
1.You need to select "change layout (ctrl+F8)",
a small window comes, it has two part -> column content & hidden fields.
then u select "Vendor" from hidden field & move it to column content.
2. at column content there is a column named "Total". u need to remove check for your column name "amount".
now select "copy" button or enter. u will find the req. report.
u can save it also by ur name.
hope its helpful to u.......
plz, reward points as a way of thanks if helpful... -
How to display header title for 0MATERIAL texts in the query output?
Dear Bwers,
I have a requirement where i need to display headers titles for 0MATERIAL texts in the query output. (example "Material description"). Any ideas on how to do this?
Thanks
RajKamal,
Its is as below:
<b>Vendor</b> <b>Vendor Name</b>
1001 --- Bright Industries
1002 --- Glow Industries
I want to display the header title "Vendor Name" as the title in the column instead of displaying the text without any header title.
Thanks
Raj
Message was edited by:
Raj Singh
Message was edited by:
Raj Singh -
Programme required for query output
Hi,
We have created a Query in system which will give output of non-printed invoices in system. User select these invoices list and prints it manually.
Now user has comeup with a requirement that he wanted a programme that selects the query output (non printed invoices) and that automatically adds the output type XXXX.
Pls let me know does anyone know about such progrmme??
Thanks in advance
Srikkyhi,
1. sorry we have some limitation in query.
2. copy the logic into Zprogram and create newly.
3. add check boxes for each invoice in teh report.
4. keep select all and deselect all push buttons on the top.
5. write a SPOOL request inside the program which converts into PDF.
6. and execute for getting print out.
or
an out put is generated automatically when you save an invoice.
requisites: a spool program has to be attached to the driver program and execute the spool by selecting it.
regards,
balajia -
Expected output for my sql query
Hi can you please tell me how to get the my expected output from the table work_invoice_hold_t
where i need to compare company code , tot_cust_no,sto_no,sales_date and trans_type='HOLD'
for example below i am comparing comp_code 1801 ,tot_cust_no,sto_no and sales_date.... when i compare them i need to get sales date record like
1801 1504522002 601 120618 1 142 HOLD Y
COMP_CODE TOT_CUST_NO STO_NO SALES_DATE CASH_NO RECEIPT_NO TRANS_TYPE PROCESSED
2300 0062090790 121 120306 3 132 HOLD Y
1801 1504522002 601 120306 1 142 HOLD Y
1801 1504522002 601 120306 1 142 UNHOLD 3
1801 1504522002 601 120618 1 142 HOLD Y
EXPECTED OUTPUT:
2300 0062090790 121 120306 3 132 HOLD Y
1801 1504522002 601 120618 1 142 HOLD YHi Thank you for providing the necessary help.
Here is another requirement for my query.
First query should be merged into second query. In the second query we are using one more table like "I_INVOICE_INFO_T_LOG_V"
that is when we put both first and second queries together i need to get the output like below:
601 STO 1504522002 120618 142 1 1801 HOLD
121 STO 0062090790 120306 132 3 2300 HOLD
table structure is:
CREATE TABLE RIMS.I_INVOICE_INFO_T_LOG_V
REG_DATE VARCHAR2(6 BYTE),
STO_NO VARCHAR2(3 BYTE),
SALES_DATE VARCHAR2(6 BYTE),
CASH_NO NUMBER(5),
RECEIPT_NO NUMBER(10),
ORDER_NO NUMBER(10),
TOT_CUST_NO VARCHAR2(13 BYTE),
CONTROL_NO NUMBER(10),
INV_ADM_COST_FR VARCHAR2(1 BYTE),
VAT_OBLIGED VARCHAR2(1 BYTE),
ART_NO VARCHAR2(8 BYTE),
SOLD_QTY NUMBER(10),
SOLD_AMOUNT NUMBER(10),
CUR_CODE VARCHAR2(3 BYTE),
ORIG_INVO VARCHAR2(10 BYTE),
CUSDEL_NO NUMBER(2),
SEQ_NO_SORT NUMBER(10),
GROUP_ID_PROD NUMBER(10),
GROUP_ID_TXT NUMBER(10),
CUSDEL_TYPE VARCHAR2(2 BYTE),
VAT_CODE VARCHAR2(10 BYTE),
VAT_RATE NUMBER(6,2),
TIMESTAMP DATE,
INV_TYPE VARCHAR2(1 BYTE),
INS_USER VARCHAR2(30 BYTE),
MACHINE VARCHAR2(64 BYTE),
SEQ NUMBER(22) NOT NULL
sample data :
SET DEFINE OFF;
Insert into RIMS.I_INVOICE_INFO_T_LOG_V
(REG_DATE, STO_NO, SALES_DATE, CASH_NO, RECEIPT_NO, ORDER_NO, TOT_CUST_NO, CONTROL_NO, INV_ADM_COST_FR, VAT_OBLIGED, ART_NO, SOLD_QTY, SOLD_AMOUNT, CUR_CODE, CUSDEL_NO, SEQ_NO_SORT, GROUP_ID_PROD, CUSDEL_TYPE, VAT_CODE, VAT_RATE, TIMESTAMP, SEQ)
Values
('120306', '121', '120306', 3, 132,
0, ' 0062090790', 0, '0', '1',
'40043234', 8, 20800, 'DKK',
0, 0, 0, '01',
'0', 2500, TO_DATE('10/21/2005 00:00:00', 'MM/DD/YYYY HH24:MI:SS'), 916052);
Insert into RIMS.I_INVOICE_INFO_T_LOG_V
(REG_DATE, STO_NO, SALES_DATE, CASH_NO, RECEIPT_NO, ORDER_NO, TOT_CUST_NO, CONTROL_NO, INV_ADM_COST_FR, VAT_OBLIGED, ART_NO, SOLD_QTY, SOLD_AMOUNT, CUR_CODE, CUSDEL_NO, SEQ_NO_SORT, GROUP_ID_PROD, CUSDEL_TYPE, VAT_CODE, VAT_RATE, TIMESTAMP, SEQ)
Values
('120306', '601', '120306', 1, 142,
0, ' 1504522002', 0, '0', '1',
'40047760', 2, 200, 'GBP',
0, 0, 0, '01',
'0', 1750, TO_DATE('10/21/2005 00:00:00', 'MM/DD/YYYY HH24:MI:SS'), 916053);
Insert into RIMS.I_INVOICE_INFO_T_LOG_V
(REG_DATE, STO_NO, SALES_DATE, CASH_NO, RECEIPT_NO, ORDER_NO, TOT_CUST_NO, CONTROL_NO, INV_ADM_COST_FR, VAT_OBLIGED, ART_NO, SOLD_QTY, SOLD_AMOUNT, CUR_CODE, CUSDEL_NO, SEQ_NO_SORT, GROUP_ID_PROD, CUSDEL_TYPE, VAT_CODE, VAT_RATE, TIMESTAMP, SEQ)
Values
('120618', '601', '120618', 1, 142,
0, ' 1504522002', 0, '0', '1',
'20057057', 2, 400, 'GBP',
0, 0, 0, '01',
'0', 1500, TO_DATE('10/21/2005 00:00:00', 'MM/DD/YYYY HH24:MI:SS'), 916054);
Insert into RIMS.I_INVOICE_INFO_T_LOG_V
(REG_DATE, STO_NO, SALES_DATE, CASH_NO, RECEIPT_NO, ORDER_NO, TOT_CUST_NO, CONTROL_NO, INV_ADM_COST_FR, VAT_OBLIGED, ART_NO, SOLD_QTY, SOLD_AMOUNT, CUR_CODE, CUSDEL_NO, SEQ_NO_SORT, GROUP_ID_PROD, VAT_CODE, VAT_RATE, TIMESTAMP, SEQ)
Values
('051020', '262', '051020', 11, 16,
0, ' 1555792009', 0, '0', '1',
'50043993', 3, 4800, 'GBP',
0, 0, 0,
'0', 1750, TO_DATE('10/21/2005 00:00:00', 'MM/DD/YYYY HH24:MI:SS'), 916055);
for example:
Second query
SELECT DISTINCT workhold.sto_no AS bu_code,
'STO' AS Bu_Type,
AND workhold.processed='Y'...
and ( first query condition)
First query.
WITH got_cnt AS
SELECT w.* -- or list columns you want
, COUNT (CASE WHEN trans_type = 'HOLD' THEN 1 END)
OVER (PARTITION BY comp_code, tot_cust_no, sales_date)
AS hold_cnt
, COUNT (CASE WHEN trans_type = 'UNHOLD' THEN 1 END)
OVER (PARTITION BY comp_code, tot_cust_no, sales_date)
AS unhold_cnt
FROM work_invoice_hold_t w
SELECT sto_no as bu_code,'STO' as bu_type,tot_cust_no as cust_no,sales_date,receipt_no,cash_no as till_no,comp_code,trans_type-- or list columns you want
FROM got_cnt
WHERE hold_cnt = 0
OR unhold_cnt = 0
First query output:
601 STO 1504522002 120618 142 1 1801 HOLD
121 STO 0062090790 120306 132 3 2300 HOLD
Second Query:
SELECT DISTINCT workhold.sto_no AS bu_code,
'STO' AS Bu_Type,
workhold.Tot_Cust_No AS Cust_No,
workhold.Sales_Date AS Sales_Date,
workhold.Receipt_No,
workHOLD.Cash_No AS Till_No,
workhold.Comp_Code,
workhold.Trans_Type AS on_hold_flag
FROM WORK_INVOICE_HOLD_V workhold,
I_INVOICE_INFO_T_LOG_V invlog
WHERE
TRIM (workhold.Tot_Cust_No) = TRIM (invlog.Tot_Cust_No)
AND TRIM (workhold.Cash_No) = TRIM (invlog.Cash_No)
AND TRIM (workhold.sales_date) = TRIM (invlog.sales_date)
AND TRIM (workhold.Receipt_No) = TRIM (invlog.Receipt_No)
AND TRIM (workhold.Sto_No) = TRIM (invlog.Sto_No)
AND workhold.processed='Y'
output for second query:
601 STO 1504522002 120618 142 1 1801 HOLD
601 STO 1504522002 120306 142 1 1801 HOLD
121 STO 0062090790 120306 132 3 2300 HOLD
expected output:
after checking the conditions for both 1 and 2 queries i need to get the output like below.
601 STO 1504522002 120618 142 1 1801 HOLD
121 STO 0062090790 120306 132 3 2300 HOLDEdited by: 891933 on Oct 2, 2012 1:18 AM -
Hi Team,
I have build two query report.
Q1 qury:
SELECT hp.party_name "CUSTOMER_NAME",
hl.address1,
hl.address2,
hl.address3,
hl.city,
hl.state,
hl.postal_code,
hca.account_number "CUSTOMER_CODE",
aps.cash_receipt_id,
hcsu.LOCATION "LOCATION", -- Added by Kanchan
rct.trx_number "INVOICE_NUMBER",
--ar.receipt_number,
HOU.Name "Company Name",
rbs.NAME "SOURCE_NAME",
aps.GL_DATE "GL DATE",
rct.trx_date "INVOICE_DATE",
--SUBSTR(TRUNC(rct.trx_date),4) "INVOICE_PERIOD",
rct.term_due_date "DUE_DATE",
arc.NAME "COLLECTOR_NAME",
rctl.line_number "SR_NO",
DECODE (rctl.memo_line_id, NULL, rctt.description, decode( rctt.description, arml.description, rctt.description , rctt.description || ' ' || CHR (10) || arml.description)) "DESCRIPTION",
rctl.uom_code "UNIT_OF_MEASURE",
rctl.quantity_invoiced "QUANTITY",
rctl.unit_selling_price "UNIT_RATE",
ROUND (rctl.extended_amount) "AMOUNT",
arn.text "COMMENTS",
rct.customer_trx_id "TRX_ID",
rct.org_id "ORG_ID",
rct.INVOICE_CURRENCY_CODE,
hca.cust_account_id "CUSTOMER_ID"
FROM ra_customer_trx_all rct,
ra_cust_trx_types_all rctt,
ar_payment_schedules_all aps,
-- ar_receivable_applications_all acra,
-- ar_cash_receipts_all ar,
ra_batch_sources_all rbs,
hz_cust_site_uses_all hcsu,
hz_cust_acct_sites_all hcas,
hz_party_sites hps,
hz_cust_accounts hca,
hr_all_organization_units HOU,
hz_parties hp,
hz_locations hl,
ra_customer_trx_lines_all rctl,
ar_memo_lines_all_tl arml,
hz_customer_profiles hcp,
ar_collectors arc,
ar_notes arn
WHERE rct.cust_trx_type_id = rctt.cust_trx_type_id
AND rctt.TYPE = 'INV'
AND rct.complete_flag = 'Y'
AND rct.batch_source_id = rbs.batch_source_id
-- AND acra.cash_receipt_id = ar.cash_receipt_id
-- and acra.applied_customer_trx_id = rct.customer_trx_id
AND rct.org_id = rbs.org_id
and hou.organization_id=rct.LEGAL_ENTITY_ID
AND rct.bill_to_customer_id = hca.cust_account_id
AND aps.customer_trx_id = rct.customer_trx_id
AND hca.party_id = hp.party_id
AND rct.bill_to_site_use_id = hcsu.site_use_id
AND rct.org_id = hcsu.org_id
AND hcsu.cust_acct_site_id = hcas.cust_acct_site_id
AND hcsu.org_id = hcas.org_id
AND hcas.party_site_id = hps.party_site_id
AND hps.location_id = hl.location_id
AND rct.customer_trx_id = rctl.customer_trx_id
AND rct.org_id = rctt.org_id
AND rctt.org_id = rctl.org_id
AND rctl.memo_line_id = arml.memo_line_id(+)
AND rctl.line_type = 'LINE'
AND rct.bill_to_site_use_id = hcp.site_use_id(+)
AND hcp.collector_id = arc.collector_id(+)
AND rct.customer_trx_id = arn.customer_trx_id(+)
AND Nvl(arn.note_id,0) = Nvl((SELECT MAX (note_id)
FROM ar_notes arnt
WHERE arnt.customer_trx_id = rct.customer_trx_id),0)
AND rct.org_id = :p_org_id
--AND rct.batch_source_id = :p_batch_src_id
AND TRUNC(aps.gl_date) BETWEEN TRUNC(:p_trx_date_low) AND TRUNC(:p_trx_date_high)
--AND ar.receipt_number='660754'
--and hca.cust_account_id=937288
and hca.cust_account_id=5436 --291784 ----5637 --5436
-- and rct.trx_number= 15762455 --15195934 --15044822
-- AND hca.account_number ='NDDGSP035'
&LP_TRX_NO
&LP_CUST_NO
ORDER BY hca.account_number,
rct.trx_date,
rctl.line_number
and Q2 query :
select customer_id,
NVL(receipt_amount+receipt_amount2,0)Payment
from
SELECT distinct hca.cust_account_id "CUSTOMER_ID" ,
(SELECT DISTINCT
--e.customer_id CUST_ID,
SUM((a.amount) * NVL (a.exchange_rate, 1)) Receipt_Amount
FROM ar_cash_receipts_all a,
ar_cash_receipt_history_all b,
ar_receipt_classes d,
ar_customers e,
hz_party_sites hzps,
xx_ar_addresses_v g,
hz_cust_acct_sites_all h,
hz_cust_site_uses_all f,
hr_organization_units_v i
WHERE b.cash_receipt_id = a.cash_receipt_id
AND a.org_id = i.organization_id
AND a.receipt_method_id = d.receipt_class_id
AND e.customer_id=g.customer_id
AND hzps.party_site_id = h.party_site_id
AND h.party_site_id = g.party_site_id
AND f.site_use_code = 'BILL_TO'
AND f.cust_acct_site_id = h.cust_acct_site_id
AND g.language_description = 'American English'
AND b.first_posted_record_flag = ('Y')
--and e.customer_id=937288
and e.customer_id= hca.cust_account_id --5436 --291784 --5436
AND f.site_use_id = a.customer_site_use_id
AND E.CUSTOMER_ID = A.PAY_FROM_CUSTOMER ---- ADDED
AND TRUNC (b.gl_date) BETWEEN TRUNC(:p_trx_date_low) AND TRUNC(:p_trx_date_high)
AND a.org_id = :p_org_id) Receipt_amount,
( SELECT
distinct --e.customer_id CUST_ID, --SMAN_10OCT2013_Added distinct_Requested by Biju
SUM((-1 * a.amount) * NVL (a.exchange_rate, 1)) Receipt_AMOUNT
FROM ar_cash_receipts_all a,
ar_cash_receipt_history_all b,
ar_receipt_classes d,
xx_ar_addresses_v g,
ar_customers e,
hz_party_sites hzps,
hz_cust_acct_sites_all h,
hz_cust_site_uses_all f,
hr_organization_units_v i
WHERE b.cash_receipt_id = a.cash_receipt_id
AND a.org_id = i.organization_id
AND a.receipt_method_id = d.receipt_class_id
AND e.customer_id=g.customer_id
AND hzps.party_site_id = h.party_site_id
AND h.party_site_id = g.party_site_id
AND f.site_use_code = 'BILL_TO'
AND f.cust_acct_site_id = h.cust_acct_site_id
AND g.language_description = 'American English'
AND a.status IN ('NSF', 'REV', 'STOP')
AND a.reversal_date IS NOT NULL
AND b.status = 'REVERSED'
AND E.CUSTOMER_ID = A.PAY_FROM_CUSTOMER ---- ADDED
AND f.site_use_id = a.customer_site_use_id
--and e.customer_id=937288
AND e.customer_id= hca.cust_account_id --5436 --291784 --
AND TRUNC (b.gl_date) BETWEEN TRUNC(:p_trx_date_low) AND TRUNC(:p_trx_date_high)
AND a.org_id = :p_org_id
) receipt_amount2
FROM ra_customer_trx_all rct,
ra_cust_trx_types_all rctt,
ar_payment_schedules_all aps,
ra_batch_sources_all rbs,
hz_cust_site_uses_all hcsu,
hz_cust_acct_sites_all hcas,
hz_party_sites hps,
hz_cust_accounts hca,
hr_all_organization_units HOU,
hz_parties hp,
hz_locations hl,
ra_customer_trx_lines_all rctl,
ar_memo_lines_all_tl arml,
hz_customer_profiles hcp,
ar_collectors arc,
ar_notes arn
WHERE rct.cust_trx_type_id = rctt.cust_trx_type_id
AND rctt.TYPE = 'INV'
AND rct.complete_flag = 'Y'
AND rct.batch_source_id = rbs.batch_source_id
AND rct.org_id = rbs.org_id
and hou.organization_id=rct.LEGAL_ENTITY_ID
AND rct.bill_to_customer_id = hca.cust_account_id
AND aps.customer_trx_id = rct.customer_trx_id
AND hca.party_id = hp.party_id
AND rct.bill_to_site_use_id = hcsu.site_use_id
AND rct.org_id = hcsu.org_id
AND hcsu.cust_acct_site_id = hcas.cust_acct_site_id
AND hcsu.org_id = hcas.org_id
AND hcas.party_site_id = hps.party_site_id
AND hps.location_id = hl.location_id
AND rct.customer_trx_id = rctl.customer_trx_id
AND rct.org_id = rctt.org_id
AND rctt.org_id = rctl.org_id
AND rctl.memo_line_id = arml.memo_line_id(+)
AND rctl.line_type = 'LINE'
AND rct.bill_to_site_use_id = hcp.site_use_id(+)
AND hcp.collector_id = arc.collector_id(+)
--and hca.cust_account_id=5436 --291741--5436
AND rct.customer_trx_id = arn.customer_trx_id(+)
AND Nvl(arn.note_id,0) = Nvl((SELECT MAX (note_id)
FROM ar_notes arnt
WHERE arnt.customer_trx_id = rct.customer_trx_id),0)
AND rct.org_id = :p_org_id
AND TRUNC(aps.gl_date) BETWEEN TRUNC(:p_trx_date_low) AND TRUNC(:p_trx_date_high)
So here i am linking Q1 query with Q2 by Customer_ID data link. But after doing the same , i am getting message. Moreover, when i am running my report , my q2 query runs for all customer_id , which i already hardcoded in Q1 query.
Please help on this issue.
Regards
SachinDear Siva,
Can yoiu please run this code in sql directly , and paste here the results?
You please try as below syntax
SELECT SYSDATE,
CASE
WHEN TO_CHAR (SYSDATE, 'DAY') = 'MONDAY' THEN 'IT IS MONDAY'
WHEN TO_CHAR (SYSDATE, 'DAY') = 'TUESDAY' THEN 'IT IS TUESDAY'
END
FROM DUAL
Edited by: O.Developer on Jan 7, 2013 8:54 AM -
How to write a SQL Query without using group by clause
Hi,
Can anyone help me to find out if there is a approach to build a SQL Query without using group by clause.
Please site an example if is it so,
RegardsI hope this example could illuminate danepc on is problem.
CREATE or replace TYPE MY_ARRAY AS TABLE OF INTEGER
CREATE OR REPLACE FUNCTION GET_ARR return my_array
as
arr my_array;
begin
arr := my_array();
for i in 1..10 loop
arr.extend;
arr(i) := i mod 7;
end loop;
return arr;
end;
select column_value
from table(get_arr)
order by column_value;
select column_value,count(*) occurences
from table(get_arr)
group by column_value
order by column_value;And the output should be something like this:
SQL> CREATE or replace TYPE MY_ARRAY AS TABLE OF INTEGER
2 /
Tipo creato.
SQL>
SQL> CREATE OR REPLACE FUNCTION GET_ARR return my_array
2 as
3 arr my_array;
4 begin
5 arr := my_array();
6 for i in 1..10 loop
7 arr.extend;
8 arr(i) := i mod 7;
9 end loop;
10 return arr;
11 end;
12 /
Funzione creata.
SQL>
SQL>
SQL> select column_value
2 from table(get_arr)
3 order by column_value;
COLUMN_VALUE
0
1
1
2
2
3
3
4
5
6
Selezionate 10 righe.
SQL>
SQL> select column_value,count(*) occurences
2 from table(get_arr)
3 group by column_value
4 order by column_value;
COLUMN_VALUE OCCURENCES
0 1
1 2
2 2
3 2
4 1
5 1
6 1
Selezionate 7 righe.
SQL> Bye Alessandro -
Query tuning for data-warehousing application in Oracle 8i.
We have to pick up 24 months old data. Each month data is kept in a different partition.
2007-May month data is kept in PRESC200705 partition
SELECT r.account_id,
p.presc_num,
spm.product_id,
p.month,
t.best_call_state,
sum(p.trx_count)
FROM rlup_assigned_account r,
temp_presc_num_TEST t,
retail.prescrip_retail partition (PRESC200705) p,
sherlock.sherlock_product_mapping spm
WHERE spm.product_id like '056%'
and spm.mds6 = p.product_id
and t.CLIENT_ID = p.presc_num
and r.ndc_pyr_id = p.payer_plan
and t.best_call_state = r.ST
GROUP BY r.account_id,
p.presc_num,
spm.product_id,
p.month,
t.best_call_state
Q This Query is to be tuned
SQL> SELECT table_name,
2 partition_name,
3 high_value,
4 num_rows
5 FROM user_tab_partitions
6 ;
no rows selectedI have the following task:
Requirement:
According to the client, new partitions are created every month.
So the query should contain only the 24 most recent partions leaving one old partition every month.
So, the query becomes dynamic.
The query will have to leave one old partion every month and move ahead with the new partion created.
The total partitions accessed should not cross 24.
Is this possible?
Partition# for OCt 2007
1
2
3
4
5
6
7
24
Partition# for Nov 2007
Old|New
1
2..1
3..2
4..3
5..4
6..5
7..6
24..23
..24
Secondly, with one month data (in a partitioned table), the query takes about one hour to run.
with 24 month data accessed by the query, the query will take 24 hours to run.
I am sure that Oracle can be tuned to run on such huge data with ease and the query output can
come within seconds.. Otherwise, nobody would use oracle for datawarehousing applicaions.
Q. How do I write a dynamic query that references 24 recent partitions, using the query provided:
abc>SELECT r.account_id,
2 p.presc_num,
3 spm.product_id,
4 p.month,
5 t.best_call_state,
6 sum(p.trx_count)
7 FROM rlup_assigned_account r,
8 temp_presc_num_TEST t,
9 retail.prescrip_retail partition (PRESC200705) p,
10 sherlock.sherlock_product_mapping spm
11 WHERE spm.product_id like '056%'
12 and t.CLIENT_ID='934759'
13 and spm.mds6 = p.product_id
14 and t.CLIENT_ID = p.presc_num
15 and r.ndc_pyr_id = p.payer_plan
16 and t.best_call_state = r.ST
17 GROUP BY r.account_id,
18 p.presc_num,
19 spm.product_id,
20 p.month,
21 t.best_call_state
22 ;
retail.prescrip_retail partition (PRESC200705) p,
Partition name, PRESC200705 cannot be hardcoded into the sql.
Sql should take a range of 24 recent partitions.
And the query should execute fast too.
Now, is that what is called a challenge?
+++++++++++++++++++++++++++++++++++++++++++++++
Here are the index/constraints/explain_plan output on prescrip_retail table (which is partitioned)
as well as other tables to which prescrip_retail table is joined
This is what prescrip_retail looks like. This is the table having partitions.
It does not seem to have a primary key!
SQL> desc prescrip_retail
Name Null? Type
PRESC_NUM NUMBER
PFIER_NUM CHAR(8)
RELID NOT NULL CHAR(9)
ME_NUM NOT NULL CHAR(10)
PRODUCT_ID NOT NULL CHAR(6)
PRODUCT_FRMSTR NOT NULL CHAR(1)
PAYER_PLAN NOT NULL CHAR(6)
MONTH NOT NULL DATE
PYMT_CODE NOT NULL CHAR(1)
NRX_COUNT NOT NULL NUMBER(7)
NRX_QUANTITY NOT NULL NUMBER(9)
NRX_DOLLARS NOT NULL NUMBER(13,2)
TRX_COUNT NOT NULL NUMBER(7)
TRX_QUANTITY NOT NULL NUMBER(9)
TRX_DOLLARS NOT NULL NUMBER(13,2)
Table Size of Prescrip_Retail...
1 select table_name,tablespace_name,pct_free,pct_used,num_rows,avg_space
2 from all_tables
3* where table_name='PRESCRIP_RETAIL'
SQL> /
TABLE_NAME TABLESPACE_NAME PCT_FREE PCT_USED NUM_ROWS AVG_SPACE
PRESCRIP_RETAIL 2806673860 360
Explain Plan for the query to be tuned...
22:32:31 SQL> explain plan set statement_id='vista_query'
22:43:33 2 for
22:43:35 3 SELECT r.pfier_account_id,
22:43:41 4 p.presc_num,
22:43:41 5 spm.product_id,
22:43:41 6 p.month,
22:43:41 7 t.best_call_state,
22:43:41 8 sum(p.trx_count)
22:43:41 9 FROM rlup_assigned_account r,
22:43:41 10 temp_presc_num_TEST t,
22:43:41 11 retail.prescrip_retail partition (PRESC200705) p,
22:43:41 12 sherlock.sherlock_product_mapping spm
22:43:41 13 WHERE spm.product_id like '056%'
22:43:41 14 and spm.mds6 = p.product_id
22:43:41 15 and t.CLIENT_ID = p.presc_num
22:43:41 16 and r.ndc_pyr_id = p.payer_plan
22:43:41 17 and t.best_call_state = r.ST
22:43:41 18 GROUP BY r.pfier_account_id,
22:43:41 19 p.presc_num,
22:43:41 20 spm.product_id,
22:43:41 21 p.month,
22:43:41 22 t.best_call_state;
Explained.
SQL> select statement_id,operation,options,object_name
2 from plan_table
3 where statement_id='vista_query';
22:46:03 SQL> /
STATEMENT_ID OPERATION OPTIONS OBJECT_NAME
vista_query SELECT STATEMENT
vista_query SORT GROUP BY
vista_query HASH JOIN
vista_query TABLE ACCESS FULL TEMP_PRESC_NUM_TEST
vista_query HASH JOIN
vista_query TABLE ACCESS FULL RLUP_ASSIGNED_ACCOUNT
vista_query HASH JOIN
vista_query TABLE ACCESS FULL SHERLOCK_PRODUCT_MAPPING
vista_query TABLE ACCESS FULL PRESCRIP_RETAIL
9 rows selected.
Partition Pruning: This is supposed to provide an insight to the partitions oracle
vists internally...
I guess we can use "month>= add_months(sysdate,-24)" instead of partions too.
I don't think Oracle is visiting any partitions.
I'll also search into all_tab_partitions to verify this.
Explain_Plan for what partitions oracle visits internally (partition pruning):
SQL> ed
Wrote file afiedt.buf
1 explain plan set statement_id='vista'
2 for select * from retail.prescrip_retail
3* where month>= add_months(sysdate,-24)
SQL> /
Explained.
Elapsed: 00:00:00.05
22:13:56 SQL> select statement_id,operation,options,object_name
22:14:28 2 from plan_table
22:14:30 3 where statement_id='vista';
STATEMENT_ID OPERATION
OPTIONS OBJECT_NAME
vista SELECT STATEMENT
vista PARTITION RANGE
ITERATOR
vista TABLE ACCESS
FULL PRESCRIP_RETAIL
Elapsed: 00:00:01.00
Indexes/Constraints on PRESCRIP_RETAIL table:
SQL> ED
Wrote file afiedt.buf
1 SELECT TABLE_NAME,TABLE_TYPE,INDEX_NAME,INDEX_TYPE,PCT_FREE,STATUS,PARTITIONED
2 FROM ALL_INDEXES
3* WHERE TABLE_NAME IN ('PRESCRIP_RETAIL')
SQL> /
TABLE_NAME TABLE INDEX_NAME INDEX_TYPE PCT_FREE STATUS PAR
PRESCRIP_RETAIL TABLE BX6_PRESC_RELID BITMAP N/A YES
PRESCRIP_RETAIL TABLE BX7_PRESC_ME BITMAP N/A YES
PRESCRIP_RETAIL TABLE BX1_PRESC_PROD BITMAP N/A YES
PRESCRIP_RETAIL TABLE BX2_PRESC_PAYER BITMAP N/A YES
PRESCRIP_RETAIL TABLE BX3_PRESC_PAYERCD BITMAP N/A YES
PRESCRIP_RETAIL TABLE BX4_PRESC_PRESC BITMAP N/A YES
PRESCRIP_RETAIL TABLE BX5_PRESC_PFIER BITMAP N/A YES
7 rows selected.
SQL> ed
Wrote file afiedt.buf
1 SELECT TABLE_NAME,CONSTRAINT_NAME,CONSTRAINT_TYPE,STATUS,DEFERRABLE
2 FROM ALL_CONSTRAINTS
3* WHERE TABLE_NAME IN ('PRESCRIP_RETAIL')
SQL> /
TABLE_NAME CONSTRAINT_NAME C STATUS DEFERRABLE
PRESCRIP_RETAIL SYS_C001219 C ENABLED NOT DEFERRABLE
PRESCRIP_RETAIL SYS_C001220 C ENABLED NOT DEFERRABLE
PRESCRIP_RETAIL SYS_C001221 C ENABLED NOT DEFERRABLE
PRESCRIP_RETAIL SYS_C001222 C ENABLED NOT DEFERRABLE
PRESCRIP_RETAIL SYS_C001223 C ENABLED NOT DEFERRABLE
PRESCRIP_RETAIL SYS_C001224 C ENABLED NOT DEFERRABLE
PRESCRIP_RETAIL SYS_C001225 C ENABLED NOT DEFERRABLE
PRESCRIP_RETAIL SYS_C001226 C ENABLED NOT DEFERRABLE
PRESCRIP_RETAIL SYS_C001227 C ENABLED NOT DEFERRABLE
PRESCRIP_RETAIL SYS_C001228 C ENABLED NOT DEFERRABLE
PRESCRIP_RETAIL SYS_C001229 C ENABLED NOT DEFERRABLE
PRESCRIP_RETAIL SYS_C001230 C ENABLED NOT DEFERRABLE
PRESCRIP_RETAIL SYS_C001231 C ENABLED NOT DEFERRABLE
13 rows selected.
In all_tables:
NUM_ROWS:2806673860
AVG_SPACE:360
Here is the data size in the table.
SQL> select count(*) from PRESCRIP_RETAIL;
COUNT(*)
4602980312
Again, here is the partition information and the amount of data in each partition:
SQL> ed
Wrote file afiedt.buf
1 select
2 partition_name,SUBPARTITION_COUNT,PARTITION_POSITION,TABLESPACE_NAME,
3 NUM_ROWS
4 from all_tab_partitions
5 where table_name='PRESCRIP_RETAIL'
6* order by partition_name desc
SQL> /
PARTITION_NAME SUBPARTITION_COUNT PARTITION_POSITION TABLESPACE_NAME NUM_ROWS
PRESC200705 0 36 PRESC_PARTITION_29 141147085
PRESC200704 0 35 PRESC_PARTITION_28 140299317
PRESC200703 0 34 PRESC_PARTITION_27 140703128
PRESC200702 0 33 PRESC_PARTITION_26 132592733
PRESC200701 0 32 PRESC_PARTITION_25 145832356
PRESC200612 0 31 PRESC_PARTITION_24 136702837
PRESC200611 0 30 PRESC_PARTITION_23 137421767
PRESC200610 0 29 PRESC_PARTITION_22 140836119
PRESC200609 0 28 PRESC_PARTITION_21 131273578
PRESC200608 0 27 PRESC_PARTITION_20 134967317
PRESC200607 0 26 PRESC_PARTITION_19 130785504
PRESC200606 0 25 PRESC_PARTITION_18 131472696
PRESC200605 0 24 PRESC_PARTITION_17 138590581
PRESC200604 0 23 PRESC_PARTITION_16 126849798
PRESC200603 0 22 PRESC_PARTITION_15 137164667
PRESC200602 0 21 PRESC_PARTITION_14 126938544
PRESC200601 0 20 PRESC_PARTITION_13 135408324
PRESC200512 0 19 PRESC_PARTITION_12 123285100
PRESC200511 0 18 PRESC_PARTITION_11 121245764
PRESC200510 0 17 PRESC_PARTITION_10 122112932
PRESC200509 0 16 PRESC_PARTITION_09 119137399
PRESC200508 0 15 PRESC_PARTITION_08 123372311
PRESC200507 0 14 PRESC_PARTITION_07 112905435
PRESC200506 0 13 PRESC_PARTITION_06 119581406
PRESC200505 0 12 PRESC_PARTITION_05 123977315
PRESC200504 0 11 PRESC_PARTITION_04 118975597
PRESC200503 0 10 PRESC_PARTITION_03 125782688
PRESC200502 0 9 PRESC_PARTITION_02 117448839
PRESC200501 0 8 PRESC_PARTITION_01 122214436
PRESC200412 0 7 PRESC_PARTITION_36 124799998
PRESC200411 0 6 PRESC_PARTITION_35 125471042
PRESC200410 0 5 PRESC_PARTITION_34 118457422
PRESC200409 0 4 PRESC_PARTITION_33 119537488
PRESC200408 0 3 PRESC_PARTITION_32 121319137
PRESC200407 0 2 PRESC_PARTITION_31 115226621
PRESC200406 0 1 PRESC_PARTITION_30 119143031
36 rows selected.
Data in induvidual partition of PRESCRIP_RETAIL.
SQL> SELECT COUNT(*) FROM PRESCRIP_RETAIL PARTITION(PRESC200704);
COUNT(*)
140299317
SQL> SELECT COUNT(*) FROM PRESCRIP_RETAIL PARTITION(PRESC200703);
COUNT(*)
140703128
SQL> SELECT COUNT(*) FROM PRESCRIP_RETAIL PARTITION(PRESC200702);
COUNT(*)
132592733
SQL> SELECT COUNT(*) FROM PRESCRIP_RETAIL PARTITION(PRESC200701);
COUNT(*)
145832356
SQL> SELECT COUNT(*) FROM PRESCRIP_RETAIL PARTITION(PRESC200606);
COUNT(*)
131472696
SQL> SELECT COUNT(*) FROM PRESCRIP_RETAIL PARTITION(PRESC200605);
COUNT(*)
138590581
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Other tables info:
Index of other tables related to PRESCRIP_REATIL:
SQL> SELECT TABLE_NAME,TABLE_TYPE,INDEX_NAME,INDEX_TYPE,PCT_FREE,STATUS,PARTITIONED
2 FROM ALL_INDEXES
3 WHERE TABLE_NAME IN ('RLUP_ASSIGNED_ACCOUNT','TEMP_PRESC_NUM_TEST','SHERLOCK_PRODUCT_MAPPING');
SQL> /
TABLE_NAME TABLE INDEX_NAME INDEX_TYPE PCT_FREE STATUS PAR
SHERLOCK_PRODUCT_MAPPING TABLE SHERLOCK_PRODUCT_MAPPING_PK NORMAL 10 VALID NO
SHERLOCK_PRODUCT_MAPPING TABLE SHERLOCK_PRODUCT_MAPPING_X1 NORMAL 0 VALID NO
SHERLOCK_PRODUCT_MAPPING TABLE SHERLOCK_PRODUCT_MAPPING_BX1 BITMAP 0 VALID NO
SHERLOCK_PRODUCT_MAPPING TABLE SHERLOCK_PRODUCT_MAPPING_BX2 BITMAP 0 VALID NO
SHERLOCK_PRODUCT_MAPPING TABLE SHERLOCK_PRODUCT_MAPPING_BX3 BITMAP 0 VALID NO
RLUP_ASSIGNED_ACCOUNT TABLE BX1_RLUP_ASSIGNED_ACCT_PYR BITMAP 10 VALID NO
RLUP_ASSIGNED_ACCOUNT TABLE BX2_RLUP_ASSIGNED_ACCT_TOPLVL BITMAP 10 VALID NO
RLUP_ASSIGNED_ACCOUNT TABLE BX3_RLUP_ASSIGNED_ACCT_PBM BITMAP 10 VALID NO
RLUP_ASSIGNED_ACCOUNT TABLE BX4_RLUP_ASSIGNED_ACCT_AA_FLAG BITMAP 10 VALID NO
RLUP_ASSIGNED_ACCOUNT TABLE BX5_RLUP_ASSIGNED_ACCT_AA_CHD BITMAP 10 VALID NO
RLUP_ASSIGNED_ACCOUNT TABLE BX6_RLUP_ASSIGNED_ACCT_PBM_FLG BITMAP 10 VALID NO
RLUP_ASSIGNED_ACCOUNT TABLE BX7_RLUP_ASSIGNED_ACCT_ACCTID BITMAP 10 VALID NO
RLUP_ASSIGNED_ACCOUNT TABLE PK_RLUP_ASSIGNED_ACCOUNT NORMAL 10 VALID NO
13 rows selected.
Constraints in other tables:
SQL> SELECT TABLE_NAME,CONSTRAINT_NAME,CONSTRAINT_TYPE,STATUS,DEFERRABLE
2 FROM ALL_CONSTRAINTS
3 WHERE TABLE_NAME IN ('RLUP_ASSIGNED_ACCOUNT','TEMP_PRESC_NUM_TEST','SHERLOCK_PRODUCT_MAPPING');
TABLE_NAME CONSTRAINT_NAME C STATUS DEFERRABLE
RLUP_ASSIGNED_ACCOUNT SYS_C00637753 C ENABLED NOT DEFERRABLE
RLUP_ASSIGNED_ACCOUNT SYS_C00637754 C ENABLED NOT DEFERRABLE
RLUP_ASSIGNED_ACCOUNT SYS_C00637755 C ENABLED NOT DEFERRABLE
RLUP_ASSIGNED_ACCOUNT SYS_C00637756 C ENABLED NOT DEFERRABLE
RLUP_ASSIGNED_ACCOUNT SYS_C00637757 C ENABLED NOT DEFERRABLE
RLUP_ASSIGNED_ACCOUNT SYS_C00637758 C ENABLED NOT DEFERRABLE
RLUP_ASSIGNED_ACCOUNT SYS_C00637759 C ENABLED NOT DEFERRABLE
RLUP_ASSIGNED_ACCOUNT SYS_C00637760 C ENABLED NOT DEFERRABLE
RLUP_ASSIGNED_ACCOUNT SYS_C00637761 C ENABLED NOT DEFERRABLE
RLUP_ASSIGNED_ACCOUNT SYS_C00637762 C ENABLED NOT DEFERRABLE
RLUP_ASSIGNED_ACCOUNT PK_RLUP_ASSIGNED_ACCOUNT P ENABLED NOT DEFERRABLE
TEMP_PRESC_NUM_TEST SYS_C00640536 C ENABLED NOT DEFERRABLE
12 rows selected.
TEMP_PRESC_NUM_TEST does not contain any constraints or index. -
Issue with how to compute additional column in query output.
Hello PL/SQL Gurus/experts,
I am using Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production version
Currently i have the data in the following way -
drop table T2;
create table T2(Year, MastTot, BechTot, Tot) as select
'2008', '20000', '450000', '470000' from dual union all select
'2008', '50000', '324000', '374000' from DUAL union all select
'2009', '25000', '450000', '475000' from dual union all select
'2009', '250000', '324000', '574000' from DUAL union all select
'2010', '120000', '450000', '570000' from dual union all select
'2010', '52000', '324000', '376000' from DUAL union all select
'2011', '220000', '450000', '670000' from dual union all select
'2011', '52000', '324000', '376000' from DUAL ;I want the data to be presented in the following way (output)-
Year MastTot %Change BechTot %Change Tot %Change %Total
2009 275000 292.86 774000 0 1049000 24.29 27
2010 172000 -37.45 774000 0 946000 -9.82 24.35
2011 272000 58.14 774000 0 1046000 10.57 26.92
Total 789000 313.54 3096000 0 3885000 25.04 78.28I am using the following sql query -
select decode(grouping(Year), 0, Year, 'Total') Year,
To_Char(sum(MastTot), '999,999,999,999,999,999,999.99') "MastTot",
To_Char(sum(BechTot), '999,999,999,999,999,999,999.99') "BechTot",
To_Char(sum(Tot), '999,999,999,999,999,999,999.99') "Tot",
round((sum(Tot)/nullif(max(total_amount),0)) * 100, 2) "%Total"
From
select Year,
sum(MastTot) MastTot,
sum(BechTot) BechTot,
sum(Tot) Tot,
SUM(Tot) over() total_amount
From t2
group by Year,Tot
where Year>'2008'
group by grouping sets((Year),())
order by YearBut i am not able to fetch the %Change column. Kindly help me with that.
All efforts and help in this regard is highly appericated and i will be thankful to you ...Hello Purvesh K/jeneesh
If data turn out to the be following -
drop table T2;
create table T2(Year, MastTot, BechTot, Tot) as select
'2008', '20000', '450000', '470000' from dual union all select
'2008', '50000', '324000', '374000' from DUAL union all select
'2009', '25000', '450000', '475000' from dual union all select
'2009', '250000', '324000', '574000' from DUAL union all select
'2010', '120000', '0', '570000' from dual union all select
'2010', '52000', '0', '376000' from DUAL union all select
'2011', '220000', '450000', '670000' from dual union all select
'2011', '52000', '324000', '376000' from DUAL ;and if i use the following sql -
select year, sum(masttot), sum(change), sum(bechtot), sum(b_change), sum(tot), sum(t_change)
from (
select lead(year) over(order by year) year,
lead(masttot) over (order by year) masttot,
round((lead(masttot) over (order by year) - masttot)/nullif(masttot,0), 4) * 100 Change,
lead(bechtot) over (order by year) bechtot,
round((lead(bechtot) over (order by year) - bechtot)/nullif(bechtot,0), 4) * 100 B_Change,
lead(tot) over (order by year) tot,
round((lead(tot) over (order by year) - tot)/nullif(tot,0), 4) T_Change
from (
select year, sum(masttot) masttot, sum(bechtot) bechtot, sum(tot) tot
from t2
group by year
order by year
) a
where year is not null
group by yearor
with t
as (
select year,masttot,lag(masttot) over(order by year) prevm,
BechTot,lag(BechTot) over(order by year) prevb,
tot,lag(Tot) over(order by year) prevt,
sum(tot) over(order by null) sm_t
from(
select Year,
sum(MastTot) MastTot,
sum(BechTot) BechTot,
sum(Tot) Tot
From t2
group by Year
select year,sum(masttot) masttot,
sum(((masttot-prevm)/nullif(prevm,0))*100) Perc_m,
sum(BechTot) bechtot,
sum(((BechTot-prevb)/nullif(prevb,0))*100) Perc_b,
sum(tot) tot,sum(((tot-prevt)/nullif(prevt,0))*100) Perc_t,
sum((tot/nullif(sm_t,0))*100) perc_total
from t
where year > 2008
group by rollup(year);then it is not giving the correct result as in case of 2010 to 2011 in %B (Bechelor) total there is 100% change as from in year 2010 sum(bechtot)=0 and in year 2011 it is 774000.
Whats wrong with this ..........
Thanks in advance for your help/effort and valuable
Edited by: user555994 on Oct 15, 2012 5:24 AM
Maybe you are looking for
-
How get all released production orders
Hi experts, I need to get all released Production Orders for a specific plant. I noticed that usually you don´t select directly from table AUFK. Most of people use function module WCFS_STTXT_GET to get the status of an order. I know that table AUFK h
-
All but one of my iTunes Video's on my laptap lost its sound for some reason. Can anyone suggest a cause and solution.
-
Sqlldr using Nextval and Currval to load 3 databases
I am trying to load 3 tables from a flat file and when i use the Nextval on a sequence field it loads the table fine, the issue is with the 3rd check below when i try to sequence the records on that table using the same sequence field from the first
-
Dynamic Column Formula based on Prompt
Hi, i've defined a prompt and a presentation variable associated called "Scenario". It can assume values "Actual" or "Budget" My Subject Area contains vary dimensions and a fact table called "Productivity Measures" with following fields: "Productivit
-
SE63 - Translating subscreen data
Dear Colleagues, i have translated the field labels for the data elements from DE to EN. The data elements belong to a subscreen. I logged in with language EN and checked the layout in screen painter. All labels are shown in language EN. But when i s