Join 25 M with 200 M - Query Issue
I have 2 tables, CUSTOMER and CUSTOMER Transaction. CUSTOMER has 25 M records and CUSTOMER TRANSACTION has 200 M records. I need to get the count from CUSTOMER TRANSACTION divided by transaction type. below is my tables.
CUSTOMER
========
CUST_ID LOC_ID (OTHER COLUMNS)
12345 001
23456 002
67890 910
54298 789
16754 909CUSTOMER TRANSACTION
====================
CUST_ID LOC_ID TRANSACTION_TYPE DATE (OTHER COLUMNS)
12345 001 CREDIT 01-jan-01
12345 001 DEBIT 02-jan-02
12345 001 CHEQUE 03-jan-03
12345 001 CASH 04-jan-04
12345 001 CASH 05-jan-06
12345 001 CASH 11-feb-11
54298 789 CREDIT 01-jan-01
54298 789 CREDIT 02-jan-01I need to have below output
CUST_ID LOC_ID CREDIT DEBIT CASH TOTAL
12345 001 1 1 3 5
23456 002 0 0 0 0
67890 910 0 0 0 0
54298 789 2 0 0 2
16754 909 0 0 0 0
54298 789 0 0 0 0
SELECT C.CUST_ID, C.LOC_ID, CT.TOTAL, CT.CREDIT, CT.DEBIT, CT.CASH
FROM
CUSTOMER C LEFT OUTER JOIN
select CUST_ID,
LOC_ID,
COUNT(*) TOTAL,
SUM(CASE WHEN TRANSACTION_TYPE = 'CREDIT',1,0) CREDIT,
SUM(CASE WHEN TRANSACTION_TYPE = 'DEBIT',1,0 END) DEBIT,
SUM(CASE WHEN TRANSACTION_TYPE = 'CASH',1,0 END) CASH
FROM CUSTOMER_TRANSACTION
GROUP BY CUST_ID, LOC_ID
) CT
ON C.CUST_ID = CT.CUST_ID and C.LOC_ID = CT.LOC_IDNow my CUSTOMER table itself is joined with other 5 tables, with left outer join to get other information.I am joining the count as above. But i am facing severe performance issue, as it does group by on 200 M records in CUSTOMER_TRANSACTION and then joining this result set with CUSTIMER table using left outer join.
Can some one help me on how to write efficient query?
ace_friends22 wrote:
The problem with this query is, it takes lots of time to reqturn the result set.Of course. You cannot expect it to be fast - not with the amount of I/O that needs to be done.
The simple and harsh fact is that the more data there is for the SQL to crunch, the slower it will be, as I/O is the slowest and most expensive operation on a database.
I just wanted to know if there is better way of writing this qyery?There's 2 basic ways to address this. Do less I/O. Do smarter I/O.
Doing less I/O means using optimal I/O paths to get to the relevant data. Like indexes. Or partitions. Or both. And ensuring the CBO comes up with a sane execution plan and not one based on none or skewed statistics. Etc.
Doing smarter I/O means trying to eliminate some of the I/O latency using parallel processing. Oracle supports both parallel DML and DDL. And (for example), instead of having a single process crunching 20 million rows, you could use 20 parallel processing each doing around a million rows - assuming of course you have the CPU capacity and 20 I/O intensive processes will not overload the I/O subsystem.
More than that... get something like Oracle's Exadata storage cells that provide a 40Gb I/O fabric layer and a very intelligent storage server...
And keep a firm grip on the realities of computing with regards your performance expectations.
Similar Messages
-
Ora-28509 and ora-28511 when attempting to join oracle with postgresql in query
I have attempted to run the following statement.
select a."uri", b.person_id from "sources"@postgresql a, ct_person_src_ref_store b where decoder(b.source_uri) = a."id";
This is the error I get.
ERROR at line 1:
ORA-28511: lost RPC connection to heterogeneous remote agent using
SID=ORA-28511: lost RPC connection to heterogeneous remote agent using
SID=(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=localhost)(PORT=1521))(CONNECT_DAT
A=(SID=posgre133)))
ORA-28509: unable to establish a connection to non-Oracle system
ORA-02063: preceding line from POSTGRESQL
Process ID: 116908
Session ID: 5197 Serial number: 49491
I have a resulting trace file from having HS_FDS_TRACE_LEVEL = DEBUG. It's kind of long (490 lines). I'm hesitant to paste the whole log into this posting. Is there a certain part of the trace file that I can post that would assist in helping me determine the cause of the error?
ThanksThat works now ....
When we ask the Postgres driver which columns/data types are in that table it reports:
Entered hgopcda at 2014/04/16-20:59:52
Column:27(uri): dtype:-1 (LONGVARCHAR), prc/scl:8190/0, nullbl:1, octet:0, sign:1, radix:10
Exiting hgopcda, rc=0 at 2014/04/16-20:59:52
Which then leads to:
SQL text from hgopars, id=1, len=32 ...
00: 53454C45 43542022 6964222C 22757269 [SELECT "id","uri]
10: 22204652 4F4D2022 736F7572 63657322 [" FROM "sources"]
Column:1(id): dtype:-5 (BIGINT), prc/scl:19/0, nullbl:0, octet:0, sign:1, radix:0
Exiting hgopcda, rc=0 at 2014/04/16-21:05:15
Entered hgopcda at 2014/04/16-21:05:15
Column:2(uri): dtype:-1 (LONGVARCHAR), prc/scl:8190/0, nullbl:1, octet:8190, sign:1, radix:0
Exiting hgopcda, rc=0 at 2014/04/16-21:05:15
hgodscr, line 464: Printing hoada @ 0x1ab8820
MAX:2, ACTUAL:2, BRC:1, WHT=5 (SELECT_LIST)
hoadaMOD bit-values found (0x20:NEGATIVE_HOADADTY,0x200:TREAT_AS_CHAR)
DTY NULL-OK LEN MAXBUFLEN PR/SC CST IND MOD NAME
-5 BIGINT N 8 8 0/ 0 0 0 20 id
-1 LONGVARCHAR Y 0 0 0/ 0 0 0 220 uri
Exiting hgodscr, rc=0 at 2014/04/16-21:05:15
=> so far so good. The gateway exists from that routine and here it can't locate the database process anymore:
Exiting hgodscr, rc=0 at 2014/04/16-21:05:15
HS Agent received unexpected RPC disconnect
Network error 1004: NCR-01004: NCRS: Write error.
Could you please upload the alert.log details matching that timstamp?
- Klaus -
Performance issue with the Select query
Hi,
I have an issue with the performance with a seclet query.
In table AFRU - AUFNR is not a key field.
So i had selected the low and high values into s_reuck and used it in Where condition.
Still i have an issue with the Performance.
SELECT SINGLE RUECK
RMZHL
IEDD
AUFNR
STOKZ
STZHL
FROM AFRU INTO table t_AFRU
FOR ALL ENTRIES IN T_ZSCPRT100
WHERE RUECK IN S_RUECK AND
AUFNR = T_ZSCPRT100-AUFNR AND
STOKZ = SPACE AND
STZHL = 0.
I had also cheked by createing an index for AUFNR in the table AFRU...it does not help.
Is there anyway that we can declare Key field while declaring the Internal table....?
ANy suggestions to fix the performance issue is apprecaited!
Regards,
KittuHi,
Thank you for your quick response!
Rui dantas, i have lill confusion...this is my code below :
data : t_zscprt type standard table of ty_zscprt,
wa_zscprt type ty_zscprt.
types : BEGIN OF ty_zscprt100,
aufnr type zscprt100-aufnr,
posnr type zscprt100-posnr,
ezclose type zscprt100-ezclose,
serialnr type zscprt100-serialnr,
lgort type zscprt100-lgort,
END OF ty_zscprt100.
data : t_zscprt100 type standard table of ty_zscprt100,
wa_zscprt100 type ty_zscprt100.
Types: begin of ty_afru,
rueck type CO_RUECK,
rmzhl type CO_RMZHL,
iedd type RU_IEDD,
aufnr type AUFNR,
stokz type CO_STOKZ,
stzhl type CO_STZHL,
end of ty_afru.
data : t_afru type STANDARD TABLE OF ty_afru,
WA_AFRU TYPE TY_AFRU.
SELECT AUFNR
POSNR
EZCLOSE
SERIALNR
LGORT
FROM ZSCPRT100 INTO TABLE T_ZSCPRT100
FOR ALL ENTRIES IN T_ZSCPRT
WHERE AUFNR = T_ZSCPRT-PRTNUM
AND SERIALNR IN S_SERIAL
AND LGORT IN S_LGORT.
IF sy-subrc <> 0.
MESSAGE ID 'Z2' TYPE 'I' NUMBER '41'. "BDCG87
stop."BDCG87
ENDIF.
ENDIF.
SELECT RUECK
RMZHL
IEDD
AUFNR
STOKZ
STZHL
FROM AFRU INTO TABLE T_AFRU
FOR ALL ENTRIES IN T_ZSCPRT100
WHERE RUECK IN S_RUECK AND
AUFNR = T_ZSCPRT100-AUFNR AND
STOKZ = SPACE AND
STZHL = 0.
Using AUFNR, get AUFPL from AFKO
Using AUFPL, get RUECK from AFVC
Using RUEKC, read AFRU
In other words, one select joining AFKO <-> AFVC <-> AFRU should get what you want.
This is my select query, would you want me to write another select query to meet this criteria..
From AUFNR> I will get AUFPL from AFKO> BAsed on AUFPL I will get RUECK, based on RUEKC i need to read AFRU..but i need to select few field from AFRu based on AUFNR....
ANy suggestions wil be appreciated!
Regards
Kittu -
How to join GRPO with AP invoice thru query ?
hi all,
How to join GRPO with AP invoice in sql query ?
JeyakanthanHi Jeyakanthan
Are you using query in SAP Business One or outside the system? If you select the tables in SAP Business One as OPCH and OPDN then no inner join will appear, as the links sit on the line level. You will need PCH1 and PDN1. The link can be found in both directions, but bear in mind that 1 AP Invoice could be based on more than 1 Goods Receipt PO. For this reason the best approach is to start at the AP Invoice line level and use the BaseType and BaseRef fields to view which lines were pulled from which Goods Receipt PO's.
Kind regards
Peter Juby -
Performance issue after Upgrade from 4.7 to ECC 6.0 with a select query
Hi All,
There is a Performance issue after Upgrade from 4.7 to ECC 6.0 with a select query in a report painter.
This query is working fine when executed in 4.7 system where as it is running for more time in ECC6.0.
Select query is on the table COSP.
SELECT (FIELD_LIST)
INTO CORRESPONDING FIELDS OF TABLE I_COSP PACKAGE SIZE 1000
FROM COSP CLIENT SPECIFIED
WHERE GJAHR IN SELR_GJAHR
AND KSTAR IN SELR_KSTAR
AND LEDNR EQ '00'
AND OBJNR IN SELR_OBJNR
AND PERBL IN SELR_PERBL
AND VERSN IN SELR_VERSN
AND WRTTP IN SELR_WRTTP
AND MANDT IN MANDTTAB
GROUP BY (GROUP_LIST).
LOOP AT I_COSP .
COSP = I_COSP .
PERFORM PCOSP USING I_COSP-_COUNTER.
CLEAR: $RWTAB, COSP .
CLEAR CCR1S .
ENDLOOP.
ENDSELECT.
I have checked with the table indexes, they were same as in 4.7 system.
What can be the reson for the difference in execution time. How can this be reduced without adjusting the select query.
Thanks in advance for the responses.
Regards,
Dedeepya.Hi,
ohhhhh....... lots of problems in select query......this is not the way you should write it.
Some generic comments:
1. never use SELECT
endselect.
SELECT
into table
for all entries in table
where.
use perform statment after this selection.
2. Do not use into corresponding fields. use exact structure type.
3. use proper sequence of fields in the where condition so that it helps table go according to indexes.
e.g in your case
sequence should be
LEDNR
OBJNR
GJAHR
WRTTP
VERSN
KSTAR
HRKFT
VRGNG
VBUND
PARGB
BEKNZ
TWAER
PERBL
sequence should be same as defined in table.
Always keep select query as simple as possible and perform all other calculations etc. afterwords.
I hope it helps.
Regards,
Pranaya -
Join hint ignored - very bad query plan results
I'm trying to get a query that's being generated by SSAS to perform acceptably. Because this query is (at least partially) generated by SSAS, I don't have complete control over the query text.
The problem - The query looks roughly like this:
select
-- a bunch of columns
from
T1 -- table with ~40,000,000 rows
inner loop join T2 on T2.t2id = T1.t2id -- table with ~16,000 rows
inner loop join T3 on T3.t3id = T1.t3id -- table with ~200,000 rows inner loop join T4 on T4.t4id = T1.t4id -- table with ~200,000 rows
left loop join T5 on T5.t3id = T1.t3id and T5.t6id = T4.t6id -- table with 0 rows
where
-- some uninteresting conditions
T1 is a Fact (or Measure) table, T2, T3 and T4 are Dimension tables, T5 and T6 are involved in the filtering of the query. Every row of T1 WILL match exactly one row in each of T1, T2 and T3.
You'll note that I've hinted all of the joins - according to the documentation, using join hints forces join order (which is consistent with the plan that's produced). There's no mention that join hints can be transparently ignored by the optimizer,
but that seems to be precisely what's happening.
In the plan that results, the join to T4 is done as a hash join, with T1*T2*T3 (40,000,000 rows) on the "top", so it ends up trying to build a hash table with 40,000,000 rows, resulting in very high tempdb activity and very poor performance (I
don't know how poor - I've never let it finish).
I can see part of the reason why it's making this join choice - the estimate of T1*T2*T3 is only 35,000 rows, even though T1 has 40,000,000 rows and the join will hit on every row.
Questions:
1. What can I do to the query or the database to improve the estimate on the join to T3?
2. What can I do to the query to force the optimizer to use a loop join like I asked?
Version is SQL Server 2008 R2 SP2 Developer Edition X64.
OS is Windows 2008 R2
Machine is dual-quad-hyper-threaded CPU with 96Gb of RAM and several Tb of disk spread over 8 spindles and SSDs.
I've seen this query perform well before - I've been tuning this query for going on 7 years now and I've never seen it perform this badly that I can recall. Not sure if it's something that's changed in SP2, or something about the distribution
of data in this particular database that's changed, but something's sure changed.
-cd Mark the best replies as answers!That would indicate that there are no foreign-key constraints, or if they, they are not trusted. (Assuming here that there WHERE clause includes no filter on T1.)
That, or the statistics on T1 are giving a completely wrong estimates for the number of NULL values in t2id and t3id.
Erland Sommarskog, SQL Server MVP, [email protected]
Thanks, Erland.
There are foreign key constraints, but they're NOCHECK. I've tried creating and updating statistics on various columns of the tables involved - I'll re-check that I've got up to date statistics on all of the columns involved in these joins.
What about the join-hint being ignored? Is there anything I can do, or has something changed here recently? Interestingly, when I run this query from SSMS, I get loop-joins all around, but when SSAS runs the query, the one join always comes out
a hash join. Before I added the hints, all joins were hash joins - the hints worked on all joins but the one.
-cd Mark the best replies as answers! -
Hi,
I make query as belown to join PO with GRPO.I wnat to calculate Quantity from PO to GRPO but in my query it show duplicate record i also use distinct but useless.My query as below.
SELECT T1.DocNum [PO No], T1.DocDate [PO Date], T3.ItemCode, T3.Dscription, T3.U_CostCentre, T3.DocEntry [GRN No], T0.DocDate [GRN Date],T3.Quantity'GRIR Quantity',T2.Quantity 'PO Quantity',
T3.Quantity-T2.Quantity 'Balance Quantity'
FROM OPDN T0 , OPOR T1, POR1 T2, PDN1 T3
WHERE T1.DocEntry = T2.DocEntry
and T0.Docnum = T3.Docentry
and T3.BaseRef = T1.DocNum
and T2.ItemCode = T3.ItemCode
and T3.DocDate between [%0] and [%1]
Can any body help in this regards.
Sohail Anwar AliHi Sohail,
As i understand, you want to know till now how much of quantity stills needs to be delivered, in that case instead of trying joining two tables i would suggest to try this query which gives you
Purchase Order Document No,
Purchase Order Date,
Vendor Name,
Item Code,
Item Description,
Ordered Quantity,
Received Quantity,
Open Quantity.
as the filed OpenQty stores the Quantity yet to receive for that particular Purchase Order. As this approach is much more flexible
Query
SELECT T0.DocNum, T0.DocDate, T0.CardName, T1.ItemCode, T1.Dscription, T1.Quantity,
(T1.Quantity-T1.OpenQty) as "Recevied Quantity",
T1.OpenQty FROM OPOR T0 INNER JOIN POR1 T1 ON T0.DocEntry = T1.DocEntry WHERE T0.DocDate >=[%0] and
T0.DocDate <=[%1]
I hope this helps out your issue
regards,
Shreyas -
Joining Quotes with Orders in OBIA Siebel Sales
Hi Gurus,
I need to find a way to join the Quotes with the Order in the OOTB RPD from Siebel Sales implementation. I am trying to join with the Row_WID but i do not get any results for the below query, i want to have the the Quote number and the related Order Number and details.
select * from obaw.w_order_d a, obaw.w_order_f b, obaw.w_Quote_f c, obaw.w_quote_d d
where a.row_wid=b.row_wid
and b.row_wid=c.row_wid
and c.row_wid = d.row_wid
I am sure i am going grossly going wrong somewhere.
Quick help will be appreciated.
Regards,
AmitAmith,Is this answered Common key to join Opportunity, Quotes & Orders
Coming to your question,you established the joins wrong,here is the query i have written for you
select a.integration_id ,a.row_wid,a.vis_pr_bu_id,
b.integration_id "quote integration",b.row_wid "quote wid",b.vis_pr_bu_id "quote vis",
c.integration_id "fact int",c.quote_wid "fact quote",c.vis_pr_bu_id "fact vis"
from w_order_d a,
w_quote_d b,
w_quote_f c,
w_order_f d
where a.row_wid=b.row_wid
and b.row_wid=c.quote_wid
and a.row_wid=d.order_wid
hope answered.
Cheers,
KK
Edited by: Kranthi.K on Jun 27, 2011 9:24 PM -
Dataset query issues twice if the dataset is connected to matrix and used in multilookup function
hello everybody.
could not find any information if this is an intended behavior:
dataset query issues twice if the dataset is connected to matrix and used in multilookup function
parameters in both queries are the same
ssrs: 2008 r2, sharepoint 2010 integrated
sharepoint 2010: september 2014 cu
thanks in advance
Sergey VdovinHello, Wendy.
I prepared a very empty sample report for you to demonstrate the problem - with this report, i hope, there is no place to discuss the shrinking of time data retrieval.
There is one dataset, one parameter and one lookup function. The query is executed twice.
<?xml version="1.0" encoding="utf-8"?>
<Report xmlns:rd="http://schemas.microsoft.com/SQLServer/reporting/reportdesigner" xmlns:cl="http://schemas.microsoft.com/sqlserver/reporting/2010/01/componentdefinition" xmlns="http://schemas.microsoft.com/sqlserver/reporting/2010/01/reportdefinition">
<AutoRefresh>0</AutoRefresh>
<DataSources>
<DataSource Name="DataSource1">
<DataSourceReference>http://t005/ProjectBICenter/DocLib/IntegrationDBVdovin.rsds</DataSourceReference>
<rd:SecurityType>None</rd:SecurityType>
<rd:DataSourceID>7e554344-d6c2-48a5-a7f4-1d24608cb4b5</rd:DataSourceID>
</DataSource>
</DataSources>
<DataSets>
<DataSet Name="DataSet1">
<Query>
<DataSourceName>DataSource1</DataSourceName>
<CommandText>select 1 as temp, '$' as tempname</CommandText>
<rd:UseGenericDesigner>true</rd:UseGenericDesigner>
</Query>
<Fields>
<Field Name="temp">
<DataField>temp</DataField>
<rd:TypeName>System.Int32</rd:TypeName>
</Field>
<Field Name="tempname">
<DataField>tempname</DataField>
<rd:TypeName>System.String</rd:TypeName>
</Field>
</Fields>
</DataSet>
</DataSets>
<ReportSections>
<ReportSection>
<Body>
<ReportItems>
<Textbox Name="ReportTitle">
<CanGrow>true</CanGrow>
<KeepTogether>true</KeepTogether>
<Paragraphs>
<Paragraph>
<TextRuns>
<TextRun>
<Value>=Lookup(1,Fields!temp.Value,Fields!tempname.Value,"DataSet1")</Value>
<Style>
<FontFamily>Verdana</FontFamily>
<FontSize>20pt</FontSize>
</Style>
</TextRun>
</TextRuns>
<Style />
</Paragraph>
</Paragraphs>
<rd:WatermarkTextbox>Title</rd:WatermarkTextbox>
<rd:DefaultName>ReportTitle</rd:DefaultName>
<Top>0mm</Top>
<Height>10.16mm</Height>
<Width>139.7mm</Width>
<Style>
<Border>
<Style>None</Style>
</Border>
<PaddingLeft>2pt</PaddingLeft>
<PaddingRight>2pt</PaddingRight>
<PaddingTop>2pt</PaddingTop>
<PaddingBottom>2pt</PaddingBottom>
</Style>
</Textbox>
</ReportItems>
<Height>57.15mm</Height>
<Style>
<Border>
<Style>None</Style>
</Border>
</Style>
</Body>
<Width>152.4mm</Width>
<Page>
<PageFooter>
<Height>11.43mm</Height>
<PrintOnFirstPage>true</PrintOnFirstPage>
<PrintOnLastPage>true</PrintOnLastPage>
<Style>
<Border>
<Style>None</Style>
</Border>
</Style>
</PageFooter>
<PageHeight>29.7cm</PageHeight>
<PageWidth>21cm</PageWidth>
<LeftMargin>2cm</LeftMargin>
<RightMargin>2cm</RightMargin>
<TopMargin>2cm</TopMargin>
<BottomMargin>2cm</BottomMargin>
<ColumnSpacing>0.13cm</ColumnSpacing>
<Style />
</Page>
</ReportSection>
</ReportSections>
<ReportParameters>
<ReportParameter Name="ReportParameter1">
<DataType>String</DataType>
<DefaultValue>
<Values>
<Value>1</Value>
</Values>
</DefaultValue>
<Prompt>ReportParameter1</Prompt>
<ValidValues>
<DataSetReference>
<DataSetName>DataSet1</DataSetName>
<ValueField>temp</ValueField>
<LabelField>tempname</LabelField>
</DataSetReference>
</ValidValues>
</ReportParameter>
</ReportParameters>
<rd:ReportUnitType>Mm</rd:ReportUnitType>
<rd:ReportServerUrl>http://t005/ProjectBICenter</rd:ReportServerUrl>
<rd:ReportID>cd1262ef-eca7-4739-a2ce-d3ca832d5cd6</rd:ReportID>
</Report>
Sergey Vdovin -
What is the wrong with my select query
HI All,
TYPES: BEGIN OF t_equi,
equnr TYPE equi-equnr,
aedat TYPE equi-aedat,
matnr TYPE equi-matnr,
sernr TYPE equi-sernr,
kunde TYPE equi-kunde,
zzreg_date TYPE equi-zzreg_date,
zzin_indic TYPE equi-zzin_indic,
zzinvoice_num TYPE equi-zzinvoice_num,
zzinvoice_date TYPE equi-zzinvoice_date,
kund1 TYPE equz-kund1,
END OF t_equi,
DATA: it_equi TYPE TABLE OF t_equi,
SELECT equnr
aedat
matnr
sernr
kunde "Ship to
zzreg_date
zzin_indic
zzinvoice_num
zzinvoice_date
kund1 "Sold to
INTO TABLE it_equi
FROM equi AS a
INNER JOIN equz AS b
ON a~equnr = b~equnr
WHERE a~equnr IN s_equnr AND
* aedat GE gv_rdate AND
a~matnr IN s_matnr AND
a~sernr IN s_sernr AND
a~kunde IN r_shpbr_kunde AND
a~zzin_indic IN s_indic AND
b~datbi EQ c_datbi AND
b~kund1 IN r_sldbr_kund1 .
what is the wrong with this select query.. ?
its giving me error "The column name "EQUNR" is unclear ."
ThanksHi ,
write tablename or alias in select also
SELECT a~equnr and check.
Regards -
Experts,
I have compiled a Sales Analysis Query for a client who need more information than the Sales Analysis in SBO can give them.
I have found that if I only run the Months of July and August (choose these randomly) I get the correct amounts in the July and August columns.
When I add these months to the whole query, July and August gets multiplied. The more invoices I add for a specific customer the more it is multiplied.
I need to know what is wrong with the whole query. Any help would be appreciated.
Here is the July & August query that is correct:
SELECT T0.[CardCode], T0.[CardName],
(SUM(T9.Debit) - sum(T9.Credit)) AS 'July',
(SUM(T10.Debit) - sum(T10.Credit)) AS 'August'
FROM OCRD T0
LEFT JOIN JDT1 T9 ON T9.ShortName = T0.CardCode AND Month(T9.Duedate) = 7 AND Year(T9.Duedate) = 2010 AND T9.TransType in ('13','14')
LEFT JOIN JDT1 T10 ON T10.ShortName = T0.CardCode AND Month(T10.Duedate) = 8 AND Year(T10.Duedate) = 2010 AND T10.TransType in ('13','14')
WHERE T0.CardType = 'C'
Group By T0.[CardCode], T0.[CardName]
Here is the Total query that mulitplies the data per month:
SELECT T0.CardCode, T0.CardName,
(SUM(T1.Debit) - sum(T1.Credit)) AS 'Total Sales 2009', ((SUM(T1.Debit) - sum(T1.Credit))/12) AS '2009 Monthly Avg', (SUM(T2.Debit) - sum(T2.Credit)) AS 'Total Sales 2010',
((SUM(T2.Debit) - sum(T2.Credit))/Month(GetDate())) AS '2010 Monthly Avg',
(SUM(T3.Debit) - sum(T3.Credit)) AS 'January 2010',
(SUM(T4.Debit) - sum(T4.Credit)) AS 'February 2010',
(SUM(T5.Debit) - sum(T5.Credit)) AS 'March 2010',
(SUM(T6.Debit) - sum(T6.Credit)) AS 'April 2010',
(SUM(T7.Debit) - sum(T7.Credit)) AS 'May 2010',
(SUM(T8.Debit) - sum(T8.Credit)) AS 'June 2010',
(SUM(T9.Debit) - sum(T9.Credit)) AS 'July 2010',
(SUM(T10.Debit) - sum(T10.Credit)) AS 'August 2010',
(SUM(T11.Debit) - sum(T11.Credit)) AS 'September 2010',
(SUM(T12.Debit) - sum(T12.Credit)) AS 'October 2010',
(SUM(T13.Debit) - sum(T13.Credit)) AS 'November 2010',
(SUM(T14.Debit) - sum(T14.Credit)) AS 'December 2010'
FROM OCRD T0
LEFT JOIN JDT1 T1 ON T1.ShortName = T0.CardCode AND Year(T1.Duedate) = 2009 AND T1.TransType in ('13','14')
LEFT JOIN JDT1 T2 ON T2.ShortName = T0.CardCode AND Year(T2.Duedate) = 2010 AND T2.TransType in ('13','14')
LEFT JOIN JDT1 T3 ON T3.ShortName = T0.CardCode AND Month(T3.Duedate) = 1 AND Year(T3.Duedate) = 2010 AND T3.TransType in ('13','14')
LEFT JOIN JDT1 T4 ON T4.ShortName = T0.CardCode AND Month(T4.Duedate) = 2 AND Year(T4.Duedate) = 2010 AND T4.TransType in ('13','14')
LEFT JOIN JDT1 T5 ON T5.ShortName = T0.CardCode AND Month(T5.Duedate) = 3 AND Year(T5.Duedate) = 2010 AND T5.TransType in ('13','14')
LEFT JOIN JDT1 T6 ON T6.ShortName = T0.CardCode AND Month(T6.Duedate) = 4 AND Year(T6.Duedate) = 2010 AND T6.TransType in ('13','14')
LEFT JOIN JDT1 T7 ON T7.ShortName = T0.CardCode AND Month(T7.Duedate) = 5 AND Year(T7.Duedate) = 2010 AND T7.TransType in ('13','14')
LEFT JOIN JDT1 T8 ON T8.ShortName = T0.CardCode AND Month(T8.Duedate) = 6 AND Year(T8.Duedate) = 2010 AND T8.TransType in ('13','14')
LEFT JOIN JDT1 T9 ON T9.ShortName = T0.CardCode AND Month(T9.Duedate) = 7 AND Year(T9.Duedate) = 2010 AND T9.TransType in ('13','14')
LEFT JOIN JDT1 T10 ON T10.ShortName = T0.CardCode AND Month(T10.Duedate) = 8 AND Year(T10.Duedate) = 2010 AND T10.TransType in ('13','14')
LEFT JOIN JDT1 T11 ON T11.ShortName = T0.CardCode AND Month(T11.Duedate) = 9 AND Year(T11.Duedate) = 2010 AND T11.TransType in ('13','14')
LEFT JOIN JDT1 T12 ON T12.ShortName = T0.CardCode AND Month(T12.Duedate) = 10 AND Year(T12.Duedate) = 2010 AND T12.TransType in ('13','14')
LEFT JOIN JDT1 T13 ON T13.ShortName = T0.CardCode AND Month(T13.Duedate) = 11 AND Year(T13.Duedate) = 2010 AND T13.TransType in ('13','14')
LEFT JOIN JDT1 T14 ON T14.ShortName = T0.CardCode AND Month(T14.Duedate) = 12 AND Year(T14.Duedate) = 2010 AND T14.TransType in ('13','14')
WHERE T0.CardType = 'C'
Group By T0.CardCode, T0.CardNameHi,
Try this
SELECT T0.CardCode, T0.CardName,
(SUM(T1.Debit) - sum(T1.Credit)) AS 'Total Sales 2009', ((SUM(T1.Debit) - sum(T1.Credit))/12) AS '2009 Monthly Avg', (SUM(T1.Debit) - sum(T1.Credit)) AS 'Total Sales 2010',
((SUM(T1.Debit) - sum(T1.Credit))/Month(GetDate())) AS '2010 Monthly Avg',
((sum(Case DATENAME(month,T1.DueDate) when 'January' then T1.Debit else 0 end)-sum(Case DATENAME(month,T1.DueDate) when 'January' then T1.Credit else 0 end))) Jan,
(sum(Case DATENAME(month,T1.DueDate) when 'February' then T1.Debit else 0 end)-sum(Case DATENAME(month,T1.DueDate) when 'February' then T1.Credit else 0 end))[Feb],
(sum(Case DATENAME(month,T1.DueDate) when 'March' then T1.Debit else 0 end)-sum(Case DATENAME(month,T1.DueDate) when 'March' then T1.Credit else 0 end))Mar,
(sum(Case DATENAME(month,T1.DueDate) when 'April' then T1.Debit else 0 end)-sum(Case DATENAME(month,T1.DueDate) when 'April' then T1.Credit else 0 end))Apr,
(sum(Case DATENAME(month,T1.DueDate) when 'May' then T1.Debit else 0 end)-sum(Case DATENAME(month,T1.DueDate) when 'May' then T1.Credit else 0 end))May,
(sum(Case DATENAME(month,T1.DueDate) when 'June' then T1.Debit else 0 end)-sum(Case DATENAME(month,T1.DueDate) when 'June' then T1.Credit else 0 end))Jun,
(sum(Case DATENAME(month,T1.DueDate) when 'July' then T1.Debit else 0 end)-sum(Case DATENAME(month,T1.DueDate) when 'July' then T1.Credit else 0 end))Jul,
(sum(Case DATENAME(month,T1.DueDate) when 'August' then T1.Debit else 0 end)-sum(Case DATENAME(month,T1.DueDate) when 'August' then T1.Credit else 0 end))Aug,
(sum(Case DATENAME(month,T1.DueDate) when 'September' then T1.Debit else 0 end)-sum(Case DATENAME(month,T1.DueDate) when 'September' then T1.Credit else 0 end))Sep,
(sum(Case DATENAME(month,T1.DueDate) when 'October' then T1.Debit else 0 end)-sum(Case DATENAME(month,T1.DueDate) when 'January' then T1.Credit else 0 end))Oct,
(sum(Case DATENAME(month,T1.DueDate) when 'November' then T1.Debit else 0 end)-sum(Case DATENAME(month,T1.DueDate) when 'November' then T1.Credit else 0 end))Nov,
(sum(Case DATENAME(month,T1.DueDate) when 'December' then T1.Debit else 0 end)-sum(Case DATENAME(month,T1.DueDate) when 'December' then T1.Credit else 0 end)) Dec
FROM OCRD T0
LEFT JOIN JDT1 T1 ON T1.ShortName = T0.CardCode AND Year(T1.Duedate) = 2010 AND T1.TransType in ('13','14')
WHERE T0.CardType = 'C'
group by DATENAME(month,T1.DueDate), T0.CardCode, T0.CardName
Thanks,
Neetu -
Need some help with the Select query.
Need some help with the Select query.
I had created a Z table with the following fields :
ZADS :
MANDT
VKORG
ABGRU.
I had written a select query as below :
select single vkorg abgru from ZADS into it_rej.
IT_REJ is a Work area:
DATA : BEGIN OF IT_REJ,
VKORG TYPE VBAK-VKORG,
ABGRU TYPE VBAP-ABGRU,
END OF IT_REJ.
This is causing performance issue. They are asking me to include the where condition for this select query.
What should be my select query here?
Please suggest....
Any suggestion will be apprecaiated!
Regards,
DeveloperHello Everybody!
Thank you for all your response!
I had changes this work area into Internal table and changed the select query. PLease let me know if this causes any performance issues?
I had created a Z table with the following fields :
ZADS :
MANDT
VKORG
ABGRU.
I had written a select query as below :
I had removed the select single and insted of using the Structure it_rej, I had changed it into Internal table
select vkorg abgru from ZADS into it_rej.
Earlier :
IT_REJ is a Work area:
DATA : BEGIN OF IT_REJ,
VKORG TYPE VBAK-VKORG,
ABGRU TYPE VBAP-ABGRU,
END OF IT_REJ.
Now :
DATA : BEGIN OF IT_REJ occurs 0,
VKORG TYPE VBAK-VKORG,
ABGRU TYPE VBAP-ABGRU,
END OF IT_REJ.
I guess this will fix the issue correct?
PLease suggest!
Regards,
Developer. -
Hi All,
I have created a web query and assigned it to a role. I have moved the role, web templete and the query from dev to QA was able run the query fine without issues.
The problem I am having is when I make changes to the query and transport it to QA...when I run the query from the role menu it still shows the old query instead of the changed query.
Can someone please explain what are the steps I need to take when I make changes to exsisting web query in dev and move to QA and be able to see the changes. What are all the objects I need to collect. Also would like to know if there are any settings on the role menu or web templete that need to be changed and also any buffers that I need to cleared??
Any help is appriciated and will give max points.
ThanksBWdesi,
please avoid reposts - it could be that due to network issues the post got posted twice... close one of them as answered and then proceed with the other one...
Web Query issues
Arun -
We are using Jdeveloper 10.1.3.3, TopLink, ADF JSF Faces. I have an issue with TopLink named query. I am passing a value to parameter defined in the TopLink named query. The problem is that the parameter value is not being set when JSP page is loading for the first time and TopLink named query is not returning any results. When I click a button or refresh the page or some user action, then only the parameter value is set in the TopLink named query and returning the query results.Is this TopLink issue or is there any way to invoke action to fire the TopLink named query with the parameter value being passed at the time of loading JSP page ?
Our project is held up due to this issue and I will highly appreciate if someone can help on this?
Thanks in Advance.Go to your toplink map in the application navigator, select the descriptor in the structure pane and then click on the "Queries" tab in the editor pane. You should be able to configure your named query there.
Hope this helps.
Anuj -
Physical query issued by Obiee when cache is on is different and slow
When the same report runs in OBIEE 10g and cache is OFF it takes less then 1min to get results. If cache is turned ON physical query issued by Obiee is totally different and it takes 2h to get results. Has anyone experienced this with having cache on that some queries are performing poorly.
Thanks,
TatjanaWe are using BI Apps Order Management and Fulfillment Analytics and all tables are cached anyway. Dimensions used are not that huge up to 40K rows. What should I check when it comes to DB query? As I said is different than one generated when cache is disabled although both have the almost the explain plan.
Maybe you are looking for
-
WinXP booted after BIOS update cleared RAID setting, now won't boot in RAID mode
I updated the P965 Platinum BIOS to 1.7 and my system stopped booting. After much experimentation I discovered it would boot if I unplugged the monitor and mouse, so I was able to "upgrade" to 1.6, and it's working again. However, the first time it
-
Hi, I want to make a check in vendor code creation. If vendor PAN Number not maintained then system will give an error message. Who I can make this check. Please provide me suggestion. Thanks & Regards, Hemant Maurya
-
Drop Shadow on a box - correct size
I am new to Illustrator, and so apologise in advance if this is a daft question. I need to produce a graphic for a website that is 950 x 120 pixels in size. The graphic is a rectangle box with a stroke outline. I then have a drop shadow on the box. A
-
Cant my open my Mac suddenly. Please help
-
My computer keeps on crashing in windows 7 can you tell me what this means? Problem signature: Problem Event Name: BlueScreen OS Version: 6.1.7601.2.1.0.256.48 Locale ID: 1033 Additional information about the problem: BCCode: 4a