Summary query
Sorry for the vague subject line, but I don't know what to call it.First of all, here is my version info:
Oracle Database 10g Enterprise Edition Release 10.1.0.4.0 - production
PL/SQL Release 10.1.0.4.0 - Production
"CORE 10.1.0.4.0 Production."
AMT for 32-bit Windows: Version 10.1.0.4.0 - Production
NLSRTL Version 10.1.0.4.0 - Production
I'm trying to summarize some data, similar to a table of PivotChart from excel. Here is an example
CREATE
TABLE "SKIP"."PRETZELS"
(
"ID" NUMBER NOT NULL ENABLE,
"NAME" VARCHAR2(20 BYTE),
"COUNTRY" VARCHAR2(20 BYTE),
"CONSUMPTION" NUMBER,
CONSTRAINT "PRETZELS_PK" PRIMARY KEY ("ID") USING INDEX PCTFREE 10 INITRANS
2 MAXTRANS 255 STORAGE(INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS
2147483645 PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT)
TABLESPACE "USERS" ENABLE
)
PCTFREE 10 PCTUSED 40 INITRANS 1 MAXTRANS 255 NOCOMPRESS LOGGING STORAGE
(
INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645 PCTINCREASE 0
FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT
)
TABLESPACE "USERS" ;
INSERT INTO "SKIP"."PRETZELS" (ID, NAME, COUNTRY, CONSUMPTION) VALUES ('1', 'Classic Twist', 'US', '1000')
INSERT INTO "SKIP"."PRETZELS" (ID, NAME, COUNTRY, CONSUMPTION) VALUES ('2', 'Classic Twist', 'Brazil', '3030')
INSERT INTO "SKIP"."PRETZELS" (ID, NAME, COUNTRY, CONSUMPTION) VALUES ('3', 'Stick', 'US', '880')
INSERT INTO "SKIP"."PRETZELS" (ID, NAME, COUNTRY, CONSUMPTION) VALUES ('4', 'Stick', 'Germany', '190')
INSERT INTO "SKIP"."PRETZELS" (ID, NAME, COUNTRY, CONSUMPTION) VALUES ('5', 'Stick', 'Canada', '400')
INSERT INTO "SKIP"."PRETZELS" (ID, NAME, COUNTRY, CONSUMPTION) VALUES ('6', 'Soft', 'Germany', '4000')
And if I run the present:SELECT
p.name AS "NAME",
MAX (CASE WHEN p.country = 'US' THEN 'YES' ELSE 'NO' END) AS US,
MAX (CASE WHEN p.country = 'Brazil' THEN 'YES' ELSE 'NO' END) AS BRAZIL,
MAX (CASE WHEN p.country = 'Germany' THEN 'YES' ELSE 'NO' END) AS GERMANY,
MAX (CASE WHEN p.country = 'Canada' THEN 'YES' ELSE 'NO' END) AS CANADA
--
FROM skip.pretzels p
--
WHERE
p.country IN ('US', 'Brazil', 'Germany', 'Canada')
--
GROUP BY p.name
I get this (points added) to maintain the alignment of the column:NAME............US....BRAZIL..GERMANY..CANADA
Soft............NO....NO......YES......NO
Stick...........YES...NO......YES......YES
Classic Twist...YES...YES.....NO.......NO
What I want to do is to replace the 'YES' to consumption. In other wordsNAME............US....BRAZIL..GERMANY..CANADA
Soft............NO....NO......4000.....NO
Stick...........880...NO......880......400
Classic Twist...1000..3030....NO.......NO
It seems that it would be a kind of a compound SQL statement? Like replace the 'YES' with something like SELECT p.country WHERE p.consumption = 'US' and p.name =?Of course my real data are not a database of pretzel, but this should be a good analog. Moreover, my real data have a dozen 'country' and two thousand "names."
In fact, just in case eponymous, combination of country can appear several times:
SELECT
p.name AS "NAME",
NVL(TO_CHAR(SUM(CASE WHEN p.country = 'US' THEN CONSUMPTION END)),'NO') AS US,
NVL(TO_CHAR(SUM(CASE WHEN p.country = 'Brazil' THEN CONSUMPTION END)),'NO') AS BRAZIL,
NVL(TO_CHAR(SUM(CASE WHEN p.country = 'Germany' THEN CONSUMPTION END)),'NO') AS GERMANY,
NVL(TO_CHAR(SUM(CASE WHEN p.country = 'Canada' THEN CONSUMPTION END)),'NO') AS CANADA
--
FROM pretzels p
--
WHERE
p.country IN ('US', 'Brazil', 'Germany', 'Canada')
--
GROUP BY p.name
/
NAME US BRAZIL GERMANY CANADA
-------------------- ---------- ---------- ---------- ----------
Soft NO NO 4000 NO
Stick 880 NO 190 400
Classic Twist 1000 3030 NO NO
3 rows selected.
SQL>
SY.
Tags: Database
Similar Questions
-
I can't find the SQL statement in Nqqurey.log
Hi all
I installed OBIEE 11 g and BI APPS 7.9.6. I've already put the loglevel = 2. When I tried overdraft at the request of physcial in Nqquery.log. I got this newspaper:
------------------------------------
Name of the book is equal to O_JA_LEDGER (PRC GAAP)
and Fiscal Quarter is equal to 2012 Q 3
and exercise is equal to 2012
SQL logical query hash query:
29 c 96099
Set the variable LOGLEVEL = 5; SELECT "accounting". "" Name of book "saw_0 OF" Financials - GL balance sheet ' ORDER BY saw_0
]]
[2013 08-29 T 12: 32:54.000 + 08:00] [OracleBIServerComponent] [TRACK: 5] [USER-23] [] [ecid: edb4054bccf19c8a:5cea7a08:140c8514f9f: - 8000-0000000000001458] [tid: 1 has 54] [requestid: 320f0001] [sessionid: 320f0000] [username: weblogic]-General Query Info: []
Repository: Stars, business line: Core, presentation: Financials - GL-balance
]]
[2013 08-29 T 12: 32:54.000 + 08:00] [OracleBIServerComponent] [TRACK: 5] [USER 2] [] [ecid: edb4054bccf19c8a:5cea7a08:140c8514f9f: - 8000-0000000000001458] [tid: 1 has 54] [requestid: 320f0001] [sessionid: 320f0000] [username: weblogic]-logic ask (before shipping): []
Separate RqList
Sun - Ledger.Ledger name as c1 GB
OrderBy: c1 CSA
]]
[2013 08-29 T 12: 32:54.000 + 08:00] [OracleBIServerComponent] [TRACK: 5] [USER-50] [] [ecid: edb4054bccf19c8a:5cea7a08:140c8514f9f: - 8000-0000000000001458] [tid: 1 has 54] [requestid: 320f0001] [sessionid: 320f0000] [username: weblogic]-the logical query hits the plan cache []
plan
RqList < < 680766 > > [database 0:0, 0]
D1. C1 C1 [database 0:0, 0]
Of the child nodes (RqJoinSpec): < < 680770 > > [database 0:0, 0]
[RqJoinNode < < 680771 > >]
(
RqList < < 680774 > > [database 0:0, 9]
1 C1 [database 0:0, 9]
Of the child nodes (RqJoinSpec): < < 680778 > > [database 0:0, 9]
[RqJoinNode < < 680779 > >]
CacheTable T1377750624:515:22648:0CDDF8A8
) as D1
]]
[2013 08-29 T 12: 32:54.000 + 08:00] [OracleBIServerComponent] [TRACK: 5] [USER-16] [] [ecid: edb4054bccf19c8a:5cea7a08:140c8514f9f: - 8000-0000000000001458] [tid: 1 has 54] [requestid: 320f0001] [sessionid: 320f0000] [username: weblogic]-execution plan: []
RqList < < 680766 > > [database 0:0, 0]
D1. C1 C1 [database 0:0, 0]
Of the child nodes (RqJoinSpec): < < 680770 > > [database 0:0, 0]
[RqJoinNode < < 680771 > >]
(
RqList < < 680774 > > [database 0:0, 9]
1 C1 [database 0:0, 9]
Of the child nodes (RqJoinSpec): < < 680778 > > [database 0:0, 9]
[RqJoinNode < < 680779 > >]
CacheTable T1377750624:515:22648:0CDDF8A8
) as D1
]]
[2013 08-29 T 12: 32:54.000 + 08:00] [OracleBIServerComponent] [TRACK: 5] [USER-20]] [ecid: edb4054bccf19c8a:5cea7a08:140c8514f9f: - 8000-0000000000001458] [tid: 1 has 54] [requestid: 320f0001] [sessionid: 320f0000] [username: weblogic]-node performance: < < 680774 > >, narrow Row Count = 11, spacing of rows = 68 bytes []
]]
[2013 08-29 T 12: 32:54.000 + 08:00] [OracleBIServerComponent] [TRACK: 5] [USER-20]] [ecid: edb4054bccf19c8a:5cea7a08:140c8514f9f: - 8000-0000000000001458] [tid: 1 has 54] [requestid: 320f0001] [sessionid: 320f0000] [username: weblogic]-node performance: < < 680766 > > Projection, narrow Row Count = 11, spacing of rows = 68 bytes []
]]
[2013 08-29 T 12: 32:54.000 + 08:00] [OracleBIServerComponent] [TRACK: 5] [USER-34]] [ecid: edb4054bccf19c8a:5cea7a08:140c8514f9f: - 8000-0000000000001458] [tid: 1 has 54] [requestid: 320f0001] [sessionid: 320f0000] [username: weblogic]-query status: success []
]]
[2013 08-29 T 12: 32:54.000 + 08:00] [OracleBIServerComponent] [TRACK: 5] [USER-29] [] [ecid: edb4054bccf19c8a:5cea7a08:140c8514f9f: - 8000-0000000000001458] [tid: 1 has 54] [requestid: 320f0001] [sessionid: 320f0000] [username: weblogic]-physics statistical summary request: number of physical queries 1, total time 0, DB-connect time 0 (seconds) []
]]
[2013 08-29 T 12: 32:54.000 + 08:00] [OracleBIServerComponent] [TRACK: 5] [USER-24] [] [ecid: edb4054bccf19c8a:5cea7a08:140c8514f9f: - 8000-0000000000001458] [tid: 1 has 54] [requestid: 320f0001] [sessionid: 320f0000] [username: weblogic]-rows returned to the Client 11 []
]]
[2013 08-29 T 12: 32:54.000 + 08:00] [OracleBIServerComponent] [TRACK: 5] [USER-33] [] [ecid: edb4054bccf19c8a:5cea7a08:140c8514f9f: - 8000-0000000000001458] [tid: 1 has 54] [requestid: 320f0001] [sessionid: 320f0000] [username: weblogic]-logic summary query Stats: time 0, response time 0, 0 (seconds) compile time []
]]
[2013 08-29 T 12: 35:31.000 + 08:00] [OracleBIServerComponent] [TRACK: 2] [USER-0] [] [ecid: edb4054bccf19c8a:5cea7a08:140c8514f9f: - 8000 - 000000000000149 b] [tid: 1 has 54] [requestid: 320f0001] [sessionid: 320f0000] [username: weblogic] # []
There is no no instruction of Physics in the newspaper. Could someone help me?
Thank you
Tao
Query is hitting CacheTable.
Try to shoot any other column or clear the cache and run the query.
If brand aid
-
Hi Experts,
I put loglevel 2 but I could not able to see the physical motion, I can only see the logical request, below the output of said: -.
[2013-07 - 05T 17: 09:32.000 + 00:00] [OracleBIServerComponent] [TRACK: 3] [USER-0] [] [ecid: 3f3d2d8955322f32:-46609173:13fb0d45d82:-8000-000000000000042f] [tid: ff4] [requestid: a0d000b] [sessionid: a0d0000] [username: weblogic] # []
-Query SQL, logical query hash:
82330713
SET VARIABLE QUERY_SRC_CD = "report"; SELECT
s_0 0,.
'SampleSales '. "Time '." "' PER_NAME_QTR ' s_1,.
'SampleSales '. "" "" Revenue"." " Recipes' s_2
OF 'SampleSales '.
ORDER BY 1, 2 ASC NULLS LAST
EXTRACT FIRST 65001 LINES ONLY
]]
[2013-07 - 05T 17: 09:32.000 + 00:00] [OracleBIServerComponent] [TRACK: 3] [USER-23] [] [ecid: 3f3d2d8955322f32:-46609173:13fb0d45d82:-8000-000000000000042f] [tid: ff4] [requestid: a0d000b] [sessionid: a0d0000] [username: weblogic]-General Query Info: []
Repository: Stars, sector of activity: SampleSales, presentation: SampleSales
]]
[2013-07 - 05T 17: 09:32.000 + 00:00] [OracleBIServerComponent] [TRACK: 3] [USER 2] [] [ecid: 3f3d2d8955322f32:-46609173:13fb0d45d82:-8000-000000000000042f] [tid: ff4] [requestid: a0d000b] [sessionid: a0d0000] [username: weblogic]-logic ask (before shipping): []
RqList
0 GB c1,
Time.PER_NAME_QTR c2 GB,
Recipes: [DAggr (Revenue.Revenue [Time.PER_NAME_QTR])] as c3 GB
OrderBy: CSA c1, c2 asc NULLS LAST
]]
[2013-07 - 05T 17: 09:32.000 + 00:00] [OracleBIServerComponent] [TRACK: 3] [USER-50] [] [ecid: 3f3d2d8955322f32:-46609173:13fb0d45d82:-8000-000000000000042f] [tid: ff4] [requestid: a0d000b] [sessionid: a0d0000] [username: weblogic]-the logical query hits the plan cache []
plan
RqList < < 2254 > > [database 0:0, 9]
1 C1 [database 0:0, 9].
2 C2 [database 0:0, 9].
3 as c3 [database 0:0, 9]
Of the child nodes (RqJoinSpec): < < 2262 > > [database 0:0, 1]
[RqJoinNode < < 2263 > >]
CacheTable T1373069226:256:153:000000000BAAEB98
]]
[2013-07 - 05T 17: 09:32.000 + 00:00] [OracleBIServerComponent] [TRACK: 3] [USER-34]] [ecid: 3f3d2d8955322f32:-46609173:13fb0d45d82:-8000-000000000000042f] [tid: ff4] [requestid: a0d000b] [sessionid: a0d0000] [username: weblogic]-query status: success []
]]
[2013-07 - 05T 17: 09:32.000 + 00:00] [OracleBIServerComponent] [TRACK: 3] [USER-29] [] [ecid: 3f3d2d8955322f32:-46609173:13fb0d45d82:-8000-000000000000042f] [tid: ff4] [requestid: a0d000b] [sessionid: a0d0000] [username: weblogic]-physics statistical summary request: number of physical queries 1, total time 0, DB-connect time 0 (seconds) []
]]
[2013-07 - 05T 17: 09:32.000 + 00:00] [OracleBIServerComponent] [TRACK: 3] [USER-24] [] [ecid: 3f3d2d8955322f32:-46609173:13fb0d45d82:-8000-000000000000042f] [tid: ff4] [requestid: a0d000b] [sessionid: a0d0000] [username: weblogic]-rows returned to the Client 12 []
]]
[2013-07 - 05T 17: 09:32.000 + 00:00] [OracleBIServerComponent] [TRACK: 3] [USER-33] [] [ecid: 3f3d2d8955322f32:-46609173:13fb0d45d82:-8000-000000000000042f] [tid: ff4] [requestid: a0d000b] [sessionid: a0d0000] [username: weblogic]-logic summary query Stats: 0, time response time 0, 0 (seconds) compile time []
]]
[2013-07 - 05T 17: 10:59.000 + 00:00] [OracleBIServerComponent] [TRACK: 2] [USER-0] [] [ecid: 3f3d2d8955322f32:-46609173:13fb0d45d82:-8000 - 000000000000046 has] [tid: ff4] [requestid: a0d000b] [sessionid: a0d0000] [username: weblogic] # []
-Query SQL, logical query hash:
82330713
SET VARIABLE QUERY_SRC_CD = "report"; SELECT
s_0 0,.
'SampleSales '. "Time '." "' PER_NAME_QTR ' s_1,.
'SampleSales '. "" "" Revenue"." " Recipes' s_2
OF 'SampleSales '.
ORDER BY 1, 2 ASC NULLS LAST
EXTRACT FIRST 65001 LINES ONLY
]]
[2013-07 - 05T 17: 11:00.000 + 00:00] [OracleBIServerComponent] [TRACK: 2] [USER-23] [] [ecid: 3f3d2d8955322f32:-46609173:13fb0d45d82:-8000 - 000000000000046 has] [tid: ff4] [requestid: a0d000b] [sessionid: a0d0000] [username: weblogic]-General Query Info: []
Repository: Stars, sector of activity: SampleSales, presentation: SampleSales
]]
[2013-07 - 05T 17: 11:00.000 + 00:00] [OracleBIServerComponent] [TRACK: 2] [USER-34]] [ecid: 3f3d2d8955322f32:-46609173:13fb0d45d82:-8000 - 000000000000046 has] [tid: ff4] [requestid: a0d000b] [sessionid: a0d0000] [username: weblogic]-query status: success []
]]
[2013-07 - 05T 17: 11:00.000 + 00:00] [OracleBIServerComponent] [TRACK: 2] [USER-29] [] [ecid: 3f3d2d8955322f32:-46609173:13fb0d45d82:-8000 - 000000000000046 has] [tid: ff4] [requestid: a0d000b] [sessionid: a0d0000] [username: weblogic]-physics statistical summary request: number of physical queries 1, total time 0, DB-connect time 0 (seconds) []
]]
[2013-07 - 05T 17: 11:00.000 + 00:00] [OracleBIServerComponent] [TRACK: 2] [USER-24] [] [ecid: 3f3d2d8955322f32:-46609173:13fb0d45d82:-8000 - 000000000000046 has] [tid: ff4] [requestid: a0d000b] [sessionid: a0d0000] [username: weblogic]-rows returned to the Client 12 []
]]
[2013-07 - 05T 17: 11:00.000 + 00:00] [OracleBIServerComponent] [TRACK: 2] [USER-33] [] [ecid: 3f3d2d8955322f32:-46609173:13fb0d45d82:-8000 - 000000000000046 has] [tid: ff4] [requestid: a0d000b] [sessionid: a0d0000] [username: weblogic]-logic summary query Stats: time 1, response time 0, 0 (seconds) compile time []
]]
Please help me out here.
Thank you
OHO... Ok... Then I can think about caching. Is caching enabled? Can you purge the cache of all the components and try.
Seems your query hit Cache...
[2013-07 - 05T 17: 09:32.000 + 00:00] [OracleBIServerComponent] [TRACK: 3] [USER-50] [] [ecid: 3f3d2d8955322f32:-46609173:13fb0d45d82:-8000-000000000000042f] [tid: ff4] [requestid: a0d000b] [sessionid: a0d0000] [username: weblogic]-the logical query hits the plan cache []
plan
RqList <2254>> [database 0:0, 9]
1 C1 [database 0:0, 9].
2 C2 [database 0:0, 9].
3 as c3 [database 0:0, 9]
Of the child nodes (RqJoinSpec): <2262>> [database 0:0, 1]
[RqJoinNode <2263>>]
CacheTable T1373069226:256:153:000000000BAAEB98
2263>2262>2254> -
ORA: getPreference in an xslt file to transform the activity as input.
Hello
We have the following situation:
We send input to a system fields target via a transformation (xslt) the value is '01486 '. We want to use an ora:getPreference('myPrefSecurityCode') to add the field to the plan of the configuration when we deploy the process. Because the field will change to test environment for the prod environment.
"I assigned the ora:getPreference('myPrefSecurityCode') to a variable of type string named ' < SubscriberCode > < SubscriberCode xmlns =" "" xmlns: xsi = "http://www.w3.org/2001/XMLSchema-instance" xmlns:ns = "http://www.w3.org/2001/XMLSchema" xsi: type = "ns:string" > 01486 < / SubscriberCode > < / SubscriberCode >.
As you can see above, the field is assigned without any problem.
But when I try to assign the field in a Transform (xslt), I get the following error:
< bpelFault > < faultType > 0 < / faultType > < selectionFailure xmlns = "http://schemas.xmlsoap.org/ws/2003/03/business-process/" > < a name = "summary" part > < summary > query string XPath returns zero node.
The activity assign the query node returns zero node.
Either the data node or in the node xpath query was invalid.
According to BPEL4WS 1.1 spec section 14.3, check the value of line number 371 node in the BPEL source.
< / Summary > < / piece > < / selectionFailure > < / bpelFault >
Edited by: 849200 29/04/2013 06:43Hello
To pass the values of variables in the XSLT file, create an element in one of the schema of the source of your XSLT.
Use an action entitled before this transformation, and assigns the value of var preferably to the newly created variable.
Use this value to the variable to map to the required target node.I hope this helps.
Kind regards
Karan
http://learn-oraclesoa.blogspot.com/ -
In OBIEE graphics, how do you drill downs work on custom forms?
I posted this Linked In and not got an anser, so I hope someone here has an answer.
I wrote a summary query / table for a dashboard to OBIEE 10.1 with a lock down (technically, it's a 'navigation') for more information. This table breaks down the data by quarter and by geography (both are columns of discipline) and I can down this drill to work just fine. But I also this table broken down by some calculated custom fields (CASE statements WHEN) that classify the revenue / risk / Upside etc. (which are not the columns or the column values in the area in question).
When I add a drill down or sail depending on calculated columns, I get a full set of data... not a set of data filtered for this job here calculated. (Yes, I have all the EAST GUEST filters configured properly, and Yes formulas in queries source and destination are the same).
Anyone have any ideas on how to make the zoom or the navigation works on custom formulas?
Thank you
TedIt was all done using normal responses.
It is very important that the formulas are the same
(They must match letter for letter case when X = Y then 1 2 other end is different from the case when X = Y then 1 2 other end ).Also if using the prompt in the dashboard do not forget to do the titles exactly the same thing. What I do, it of create a formula and copy it and then paste everywhere else. Keep the same column headers as well.
Hope that helps.
Concerning
Chris
Published by: ChrisMarais on June 9, 2011 19:12
-
Can I do this using the functions?
Hi all
I have a select statement, this query with the category as a product:
Select c.category_name, p.product_id
product p join internal category c on c.product_id = p.product_id
Now, I have several select statements that will do the calculations and give me a line of results by year:
(I do much inner joins and pivot data to achieve this results from different tables)
Select sum (column1) year01, sum ((column2) year02, sum (column3) sum (column4) year04 year03
from tableA - calculations results for my first product
Select sum (column1) year01, sum ((column2) year02, sum (column3) sum (column4) year04 year03
from tableB - calculations results for my second product
Select sum (column1) year01, sum ((column2) year02, sum (column3) sum (column4) year04 year03
in tableC - calculations results for my third product
Each select statement are calculations that I want to attach to each product, but there is no relationship with the products.
Now I would like to join the results with my first select and get a result like:
category_name, product_id, year01, year02, year03, year04
Can I put my select calculations in functions?
If I can, how can I display the result of different functions for each product?
I need some ideas on how to achieve this.
Thank you
JohnnySo, if I understand correctly, there is no relationship between your first query and queries of summary of each product. If this is the case by default in your product_id by summary query value product would work. Something like...
SELECT
c.category_name,
p.product_id,
Max (u.year01) year01,-guess there is only 1 row by summary motion product, otherwise use sum
Max (u.year02) year02,
....
Of
product p,.
category c,
(SELECT '1' product_id, sum (column1) year01, sum ((column2) year02, sum (column3) year03, sum (column4) year04
FROM tableA - calculations results for my first product
UNION
SELECT '2', sum (column1) year01, sum ((column2) year02, sum (column3) sum (column4) year04 year03
FROM tableB - calculations results for my second product
UNION
.....) u
WHERE
c.product_id = p.product_id
and c.product_id = u.product_id
GROUP BY
c.category_name,
p.product_id -
Definition of ethnicity to group a rec per person based on several conditions
Hello
The final results will be used in a report and the table. A new category for ethnicity has been added to the database.
For this reason, the field that we use to report is no longer available. I've implemented a query
identify a record per person for ethnicity codes. The rules are if the person has a record ID as
Hispanic who use little matter that they have more than one record. If the person is Hispanic,
Then identify which category they are. If they have only a record (or multiple records in the same category),
Code for the main category. If they have more than one record in all categories (except Hispanic), then count
them as multi-ethnic.
Because the table is large and is joined with other tables for the various reports, I would like to know
If there is a way more efficient and parallel to write the sql statement. In addition, for the future, they
intend to request a report that will decompose the multiethnic in different categories to display a chart.
I thought that I would need pivot 'horizontally', or could happen "vertically," the way that the
underlying table is.
In the sample data:
1st person has two records Hispanic and European; count under "Hispanic."
2nd person has two white records and Western Europe; count as 'White '.
3rd person has two records Indian and African; count under "multiethnic".
4th person has a record of the Sioux; count under "American Indian or Alaska Native".
Here is a table of sample data:
Note: for do not need to create another table, I've hardcoded the translation of the description in the box instructionsCREATE TABLE ETHTEK ( ID VARCHAR2(5 CHAR), ETHCODE VARCHAR2(1 CHAR), ETHGROUP_CODE VARCHAR2(3 CHAR), ETHGROUP VARCHAR2(30 CHAR) ); INSERT INTO ETHTEK (ID, ETHCODE, ETHGROUP_CODE, ETHGROUP) Values ('11111', '5' ,'SEU', 'Southern European'); INSERT INTO ETHTEK (ID, ETHCODE, ETHGROUP_CODE, ETHGROUP) Values ('11111', 'H', 'SAM', 'South American'); INSERT INTO ETHTEK (ID, ETHCODE, ETHGROUP_CODE, ETHGROUP) Values ('11121', '5', 'WEU', 'Western European'); INSERT INTO ETHTEK (ID, ETHCODE, ETHGROUP_CODE, ETHGROUP) Values ('11121', '5', '5', 'White'); INSERT INTO ETHTEK (ID, ETHCODE, ETHGROUP_CODE, ETHGROUP) Values ('11122', '3', 'AF', 'African'); INSERT INTO ETHTEK (ID, ETHCODE, ETHGROUP_CODE, ETHGROUP) Values ('11122', '2', 'IND', 'Indian'); INSERT INTO ETHTEK (ID, ETHCODE, ETHGROUP_CODE, ETHGROUP) Values ('11159', '1', 'SIO', 'SIOUX');
in the following query. The actual query uses a lookup table.
Here's the sql code: (for some reason, in my preview, the upper/lower that the symbols are not, so put a comment on the lines that should be not equal in case they don't show up when posting)
What is the result of the query:WITH e AS --Ethnicity (SELECT DISTINCT id, ethcode, ethgroup_code ethgroup FROM ethtek ), h AS --Hispanic (SELECT id, ethcode FROM e WHERE ethcode = 'H'), nhm AS --Non Hispanic or Multi Ethnic (SELECT DISTINCT id, ethcode FROM e WHERE ethcode <> 'H'), -- Not Equal 'H' nh AS --Non Hispanic (SELECT id, CASE WHEN COUNT (*) OVER (PARTITION BY id) > 1 THEN 'M' ELSE ethcode END AS ethcode FROM nhm WHERE ethcode <> 'H') -- Not Equal 'H' SELECT id, ethcode, CASE WHEN ethcode = 'H' THEN 'Hispanic or Latino' WHEN ethcode = '5' THEN 'White' WHEN ethcode = 'M' THEN 'Multi-Ethnic' WHEN ethcode = '1' THEN 'American Indian or Alaskan Native' ELSE ethcode END AS ethnic_desc, CASE WHEN ethcode = 'H' THEN '4' WHEN ethcode = '4' THEN '5' WHEN ethcode = '5' THEN '6' ELSE ethcode END AS old_ethnicity_code FROM (SELECT DISTINCT h.* FROM h UNION SELECT DISTINCT nh.* FROM nh LEFT OUTER JOIN h ON nh.id = h.id WHERE h.id IS NULL) eth;
Thus, on 7 disks, we only have 4 people once.Row# ID ETHCODE ETHNIC_DESC OLD_ETHNICITY_CODE 1 11111 H Hispanic or Latino 4 2 11121 5 White 6 3 11122 M Multi-Ethnic M 4 11159 1 American Indian or Alaskan Native 1
This is the result of summary query (not included):Group Total American Indian/Alaskan Native 1 Hispanic 1 White 1 Multi-Ethnic 1 Total 4
Hello
Thanks for posting the CREATE TABLE and INSERT.
The main reason for this is to allow people who want to help you recreate the problem and test their ideas. If you post statements that don't work, it defeats the purpose.
Please check all the code before you post. Each of the INSERT statements has a lack of parentheses or quotation (usually two).If you have a parent-child relationship within the gorrace; some lines are parents of other lines, and you want the children to inherit traits from their parents.
What you posted is the usual way to the relational database for handling that: a self-join. I don't see any obvious ways to make the self-join more quickly.
You can avoid the self-join in your query if you are willing (and able) to denormalize the table and copy the traits inherited from their parents to their children. This looks like the kind of table that won't change very often, in order to maintain the standard table shouldn't be a big project. However, if the table has only 56 lines, so whatever you do with it, maybe not a great impact on the overall performance of the query.If you want to improve performance, a more scientifically to go about this is to know what that bottlenecks in the existing query and remedy.
See these discussions on how to report a tuning issue:
When your query takes too long...
HOW to: Validate a query of SQL statement tuning - model showing
Then start a new thread, setting just about the request. -
Responses showing different number of results than expected
Hi all!
I have two tables of facts (reservations, opportunity) and three dimensions (time, geography, product) in my diagram. Each of the dimension will connect both dimensions. I'm trying to compare bookings vs. opportunity. Now, when I select the criteria as long as year, quarter, month, booking, value opportunity I'd be receiving 48 ranks (I have 4 years of data so 4 * 12 months) but I get only 12 rows for the year 2006 only. I have no filters. When I check my diary as pasted below, the query actually is reach 48 records in the base data but only 12 return to the customer.
Anyone can throw some light on this issue please.
Thank you
D
+++ Administrator: 2a 0000: 2A 0009:---2010/01/19 11:49:39
-Lines 48, 1920 bytes extracted from database query id: < < 2134 > >
+++ Administrator: 2a 0000: 2A 0009:---2010/01/19 11:49:39
-Physical query response time 0 (seconds), id < < 2134 > >
+++ Administrator: 2a 0000: 2A 0009:---2010/01/19 11:49:39
-Physical statistical summary request: number of physical requests 2, total time 0, DB-connect time 0 (seconds)
+++ Administrator: 2a 0000: 2A 0009:---2010/01/19 11:49:39
-The rows returned to the Client 12
+++ Administrator: 2a 0000: 2A 0009:---2010/01/19 11:49:39
-Logic summary query Stats: 0, time response time 0, 0 (seconds) compile timeHi Dan,.
Yes, I don't see anything wrong. Or at least I think I do.
How did you get your hierarchy defined in your TIME_DIMENSION?
It is like this:
Level - keyTotal - n/a
Year - year
Quarter (quarter field as seen in the report below)
Month - month (month field as seen in the report below)Is the above correct? If so, I see a small bug. You must keep in mind that when you choose a key for a given level, it must have ONLY one parent.
If you use quarter as key to the level in the year, your instantly going to face problems. For example, if your neighborhood in 4, what is your mother going to be? 2010? 2009? 2008? The numbers 1, 2, 3 and 4 repeat each year and are not good for level key. Use instead something like "Q1 2010" or "Q42009' as a key level. It will still have only one parent. Exactly the same can be said for your key months in your time dimension. You must do something like "Jan 2010" or "2009 01".
Just give it a shot and see if it solves your problem.
Best regards
-Joe
-
Is conditional SQL processing of XDL available data models
Hello
Is it possible to have a CONDITIONAL STATEMENT in .xml (data model), based on a SQL statement that was going to be executed? Sense, based on a PARAMETER value, only the TWO queries should be run.
Ex: Lets take a system used, or if the report is run
SUMMARY = > summary query must be executed
DETAIL = > detailed queries to run.
< IF P_REPORT = SUMMARY >
< DO >
-THE QUERY SUMMARY
< END IF >
< IF P_REPORT = DETAIL >
< DO >
-DETAIL QUERY
< END IF >
Could if it you please let me know the feasibility of this in XML BI. Ask that you please point me to the documentation, if any.
Thank you
VijayaOK, I withdraw,
If it is required to be achieved. then that,
1. you need to add a report parameter values valid as 'SUMMARY' and 'DETAIL '.
2. you have 2 Add two separate petitions, no need to join them.
3 just put separate way queries in the data model or concatenated sql same datasource.
4 each of the query, to equate them with the setting something like
5 ' SUMMARY' =: PARAM_REPORT_TYPE in the query summary
6 ' DETAIL' =: PARAM_REPORT_TYPE in the query in detail
7. in execution, that which, one of the query to execute and extract the data.
8. Similarly, in the model, you can add the conditional creation of models. -
How to query the name summary of custom line of Section header information
I need a query which can help me to retrieve the contents of a header line custom section information name. We have a couple of tables Denorm when data are denormalized, the field row_name is only show the name of alias denormalized. We would like to be able to draw the contents of the line header information section name? How can we use the alias denorm name and join another table to find the associated summary name?
The following query returns the name of the line as well as the line name denorm, for a custom section, where we specify the section custom denorm table. Deserve you this to do otherwise, it depends on how you want to retrieve information. Is that what you are looking for?
SELECT ml. Name [rowName], ml.langID, dr.NAME [denormRowName], Dr. FKROWTEMPLATE, dt. GENERATED_TABLE_NAME
OF DENORM_CS_ROW dr
DENORM_CS_TABLE dt on Dr. FK_DENORM_TABLE_ID = dt.ID inner join
commonextendedattributeml ml on Dr. FKROWTEMPLATE = ml.fkOwner inner join
where dt.NAME = 'myDenormTableName. '
-
How to create the query summary results
Is there a SQL query that allows you to create a summary of the results based on the following source listed below products?
Source...
Mark object class
7A English 65
Math 7A 77
7A PE 88
7A Science 72
7B English 68
Math 7B 73
PE 7 B 69
7B Science 59
7 c English 72
Math 7 c 64
7 C PE 76
7 c Science 68
7 d English 58
7 d 89 math
7 D EP 74
7 d Science 81
Output...
English mathematics Science PE class
7 A 65 77 88 72
7 B 68 73 69 59
7 72 64 76 68
7 58 89 74 81
Thanks, AjNHello
Welcome to the forum!
Whenever you have questions, please post CREATE TABLE and INSERT statements for your sample data, so that people who want to help you can recreate the problem and test their ideas.
Always tell what version of Oracle you are using.What you asked is called a Pivot , and here's a way to do it:
SELECT class , MIN (CASE WHEN subject = 'English' THEN mark END) AS english , MIN (CASE WHEN subject = 'Maths' THEN mark END) AS maths , MIN (CASE WHEN subject = 'PE' THEN mark END) AS pe , MIN (CASE WHEN subject = 'Science' THEN mark END) AS science FROM table_x GROUP BY class ORDER BY class ;
The above query will work in Oracle 8.1 (and), but from Oracle 11.1, there is a better way: SELECT... PIVOT .
For more info on pivots, see the FAQ:
SQL and PL/SQL FAQ -
Can I make reference to a column of summary in my sql query?
Basically, the object asking all this. I have a report very complex which has many queries of data related to the "main" request One of these queries of linked data has a subquery that it contains that references the primary key of the main request. I can't do the data binding (I can, but it's useless) using this field, because it is a subquery that has the link and this particular link. I tried to create a summary column that gives me the 'first' (and the only one, so it is safe) to reference it in the SQL block, but no go. I think that it is not still possible? Anyone have any ideas? At the moment I'm referencing that I have in a PL/SQL block (: CS_PK), but it is just considered as a parameter that never happened. Does not read the analytical column. Hmmm... I'm stuck.Try it with the datalink 'column-less ". Lets say query one is named Q1 with his group G1 and query is named two Q2 with the Group G2. Now create a data link between G1 and G2 do not drag a column of G1 in G2, but dragging the group header of the G1 to G2 od group header.
Now, the detail query must be executed once for each master and you should be able to reference the value master directly in your auxiliary request.
I hope this helps.
-
How to remove the additional summary of the result of the query
All,
I create a derived table two tables and then join the result then using function group but the result is to summarize a number of additional time, can correct all my request. Here are the tables and relevant data.
CREATE TABLE SHP_DW_TEMP_DEL_WEIGHT_TB
(
CUSTOMER_ID NUMBER DEFAULT NULL,
NUMBER OF CARRIER_ID,
DATE OF BILL_DATE,
VARCHAR2 (200 BYTE) SERVICE,
NUMBER OF WEIGHT,
Create_date DATE default sysdate,
SHIPPER_ID NUMBER DEFAULT NULL
)
CREATE TABLE SHP_DW_TEMP_DEL_SPEND_TB
(
CUSTOMER_ID NUMBER DEFAULT null,
NUMBER OF CARRIER_ID,
DATE OF BILL_DATE,
VARCHAR2 (200 BYTE) SERVICE,
NUMBER OF COST,
Create_date DATE default sysdate,
SHIPPER_ID NUMBER DEFAULT of null
)
CREATE TABLE SHP_DW_INTERM_TB
(
JAVA_SESSION_ID VARCHAR2 (1000 BYTE),
USER_ID NUMBER,
CUSTOMER_ID NUMBER DEFAULT NULL,
CLIENT_NAME VARCHAR2 (100 BYTE),
NUMBER OF CARRIER_ID,
CARRIER_NAME VARCHAR2 (100 BYTE),
NUMBER OF IS_LTL_CARRIER
SHIPPER_GROUP_ID NUMBER DEFAULT NULL,
SHIPPER_ID NUMBER DEFAULT NULL,
SHIPPER_NAME VARCHAR2 (100 BYTE),
CREATE_DATE DATE DEFAULT SYSDATE,
FREIGHT_RANK NUMBER DEFAULT of null
)
Insert into msidw. SHP_DW_TEMP_DEL_WEIGHT_TB
(CUSTOMER_ID, CARRIER_ID, BILL_DATE, WEIGHT, CREATE_DATE)
Values
(664, 22, TO_DATE (FEBRUARY 25, 2014 00:00:00 ',' DD/MM/YYYY HH24:MI:SS'), 'AIRPORT INTERNATIONAL FEDEX GROUND', 602, TO_DATE (MARCH 25, 2014 04:28:29 ',' DD/MM/YYYY HH24:MI:SS'));))
Insert into msidw. SHP_DW_TEMP_DEL_WEIGHT_TB
(CUSTOMER_ID, CARRIER_ID, BILL_DATE, WEIGHT, CREATE_DATE)
Values
(664, 22, TO_DATE (11 FEBRUARY 2014 00:00:00 ',' DD/MM/YYYY HH24:MI:SS'), 'AIRPORT INTERNATIONAL FEDEX GROUND', 243, TO_DATE (MARCH 25, 2014 04:28:29 ',' DD/MM/YYYY HH24:MI:SS'));))
Insert into msidw. SHP_DW_TEMP_DEL_WEIGHT_TB
(CUSTOMER_ID, CARRIER_ID, BILL_DATE, WEIGHT, CREATE_DATE)
Values
(664, 22, TO_DATE (11 FEBRUARY 2014 00:00:00 ',' DD/MM/YYYY HH24:MI:SS'), ' FIRST INTERNATIONAL AIRPORT THE NIGHT ', 1.8, TO_DATE (MARCH 25, 2014 04:28:29 ',' ' DD/MM/YYYY HH24:MI:SS));))
Insert into msidw. SHP_DW_TEMP_DEL_WEIGHT_TB
(CUSTOMER_ID, CARRIER_ID, BILL_DATE, WEIGHT, CREATE_DATE)
Values
(664, 22, TO_DATE (11 FEBRUARY 2014 00:00:00 ',' DD/MM/YYYY HH24:MI:SS'), 'AIRPORT INTERNATIONAL ECONOMY' 8203.5, TO_DATE (MARCH 25, 2014 04:28:29 ',' DD/MM/YYYY HH24:MI:SS'));))
Insert into msidw. SHP_DW_TEMP_DEL_WEIGHT_TB
(CUSTOMER_ID, CARRIER_ID, BILL_DATE, WEIGHT, CREATE_DATE)
Values
(664, 22, TO_DATE (4 FEBRUARY 2014 00:00:00 ',' DD/MM/YYYY HH24:MI:SS'), 'AIRPORT INTERNATIONAL PRIORITY OVERNIGHT', TO_DATE 2351.1, (MARCH 25, 2014 04:28:29 ',' DD/MM/YYYY HH24:MI:SS'));))
Insert into msidw. SHP_DW_TEMP_DEL_WEIGHT_TB
(CUSTOMER_ID, CARRIER_ID, BILL_DATE, WEIGHT, CREATE_DATE)
Values
(664, 22, TO_DATE (11 FEBRUARY 2014 00:00:00 ',' DD/MM/YYYY HH24:MI:SS'), 'AIRPORT INTERNATIONAL PRIORITY OVERNIGHT', TO_DATE 2979.7, (MARCH 25, 2014 04:28:29 ',' DD/MM/YYYY HH24:MI:SS'));))
Insert into msidw. SHP_DW_TEMP_DEL_WEIGHT_TB
(CUSTOMER_ID, CARRIER_ID, BILL_DATE, WEIGHT, CREATE_DATE)
Values
(664, 22, TO_DATE (FEBRUARY 25, 2014 00:00:00 ',' DD/MM/YYYY HH24:MI:SS'), 'AIRPORT INTERNATIONAL ECONOMY' 8622.1, TO_DATE (MARCH 25, 2014 04:28:29 ',' DD/MM/YYYY HH24:MI:SS'));))
Insert into msidw. SHP_DW_TEMP_DEL_WEIGHT_TB
(CUSTOMER_ID, CARRIER_ID, BILL_DATE, WEIGHT, CREATE_DATE)
Values
(664, 22, TO_DATE (4 FEBRUARY 2014 00:00:00 ',' DD/MM/YYYY HH24:MI:SS'), 'AIRPORT INTERNATIONAL ECONOMY' 10358.4, TO_DATE (MARCH 25, 2014 04:28:29 ',' DD/MM/YYYY HH24:MI:SS'));))
Insert into msidw. SHP_DW_TEMP_DEL_WEIGHT_TB
(CUSTOMER_ID, CARRIER_ID, BILL_DATE, WEIGHT, CREATE_DATE)
Values
(664, 22, TO_DATE (18 FEBRUARY 2014 00:00:00 ',' DD/MM/YYYY HH24:MI:SS'), 'AIRPORT INTERNATIONAL PRIORITY OVERNIGHT', 2899, TO_DATE (MARCH 25, 2014 04:28:29 ',' DD/MM/YYYY HH24:MI:SS'));))
Insert into msidw. SHP_DW_TEMP_DEL_WEIGHT_TB
(CUSTOMER_ID, CARRIER_ID, BILL_DATE, WEIGHT, CREATE_DATE)
Values
(664, 22, TO_DATE (FEBRUARY 25, 2014 00:00:00 ',' DD/MM/YYYY HH24:MI:SS'), 'AIRPORT INTERNATIONAL PRIORITY OVERNIGHT', TO_DATE 2597.1, (MARCH 25, 2014 04:28:29 ',' DD/MM/YYYY HH24:MI:SS'));))
Insert into msidw. SHP_DW_TEMP_DEL_WEIGHT_TB
(CUSTOMER_ID, CARRIER_ID, BILL_DATE, WEIGHT, CREATE_DATE)
Values
(664, 22, TO_DATE (4 FEBRUARY 2014 00:00:00 ',' DD/MM/YYYY HH24:MI:SS'), 'AIRPORT INTERNATIONAL FEDEX GROUND', 121, TO_DATE (MARCH 25, 2014 04:28:29 ',' DD/MM/YYYY HH24:MI:SS'));))
Insert into msidw. SHP_DW_TEMP_DEL_WEIGHT_TB
(CUSTOMER_ID, CARRIER_ID, BILL_DATE, WEIGHT, CREATE_DATE)
Values
(664, 22, TO_DATE (18 FEBRUARY 2014 00:00:00 ',' DD/MM/YYYY HH24:MI:SS'), 'AIRPORT INTERNATIONAL ECONOMY' 9015.5, TO_DATE (MARCH 25, 2014 04:28:29 ',' DD/MM/YYYY HH24:MI:SS'));))
Insert into msidw. SHP_DW_TEMP_DEL_WEIGHT_TB
(CUSTOMER_ID, CARRIER_ID, BILL_DATE, WEIGHT, CREATE_DATE)
Values
(664, 22, TO_DATE (18 FEBRUARY 2014 00:00:00 ',' DD/MM/YYYY HH24:MI:SS'), 'AIRPORT INTERNATIONAL FEDEX GROUND', 729, TO_DATE (MARCH 25, 2014 04:28:29 ',' DD/MM/YYYY HH24:MI:SS'));))
COMMIT;
Insert into msidw. SHP_DW_TEMP_DEL_SPEND_TB
(CUSTOMER_ID, CARRIER_ID, BILL_DATE, SERVICE, COST, CREATE_DATE)
Values
(664, 22, TO_DATE (FEBRUARY 25, 2014 00:00:00 ',' DD/MM/YYYY HH24:MI:SS'), 'AIRPORT INTERNATIONAL FEDEX GROUND', 356.65, TO_DATE (MARCH 21, 2014 03:13:16 ',' DD/MM/YYYY HH24:MI:SS'));))
Insert into msidw. SHP_DW_TEMP_DEL_SPEND_TB
(CUSTOMER_ID, CARRIER_ID, BILL_DATE, SERVICE, COST, CREATE_DATE)
Values
(664, 22, TO_DATE (11 FEBRUARY 2014 00:00:00 ',' DD/MM/YYYY HH24:MI:SS'), 'AIRPORT INTERNATIONAL FEDEX GROUND', 181.19, TO_DATE (MARCH 21, 2014 03:13:16 ',' DD/MM/YYYY HH24:MI:SS'));))
Insert into msidw. SHP_DW_TEMP_DEL_SPEND_TB
(CUSTOMER_ID, CARRIER_ID, BILL_DATE, SERVICE, COST, CREATE_DATE)
Values
(664, 22, TO_DATE (11 FEBRUARY 2014 00:00:00 ',' DD/MM/YYYY HH24:MI:SS'), ' FIRST INTERNATIONAL AIRPORT THE NIGHT ', 134.45, TO_DATE (MARCH 21, 2014 03:13:16 ',' ' DD/MM/YYYY HH24:MI:SS));))
Insert into msidw. SHP_DW_TEMP_DEL_SPEND_TB
(CUSTOMER_ID, CARRIER_ID, BILL_DATE, SERVICE, COST, CREATE_DATE)
Values
(664, 22, TO_DATE (4 FEBRUARY 2014 00:00:00 ',' DD/MM/YYYY HH24:MI:SS'), 'AIRPORT INTERNATIONAL PRIORITY OVERNIGHT', TO_DATE 7267.92, (MARCH 21, 2014 03:13:16 ',' DD/MM/YYYY HH24:MI:SS'));))
Insert into msidw. SHP_DW_TEMP_DEL_SPEND_TB
(CUSTOMER_ID, CARRIER_ID, BILL_DATE, SERVICE, COST, CREATE_DATE)
Values
(664, 22, TO_DATE (11 FEBRUARY 2014 00:00:00 ',' DD/MM/YYYY HH24:MI:SS'), 'AIRPORT INTERNATIONAL ECONOMY' 27755.2, TO_DATE (MARCH 21, 2014 03:13:16 ',' DD/MM/YYYY HH24:MI:SS'));))
Insert into msidw. SHP_DW_TEMP_DEL_SPEND_TB
(CUSTOMER_ID, CARRIER_ID, BILL_DATE, SERVICE, COST, CREATE_DATE)
Values
(664, 22, TO_DATE (11 FEBRUARY 2014 00:00:00 ',' DD/MM/YYYY HH24:MI:SS'), 'AIRPORT INTERNATIONAL PRIORITY OVERNIGHT', TO_DATE 8192.35, (MARCH 21, 2014 03:13:16 ',' DD/MM/YYYY HH24:MI:SS'));))
Insert into msidw. SHP_DW_TEMP_DEL_SPEND_TB
(CUSTOMER_ID, CARRIER_ID, BILL_DATE, SERVICE, COST, CREATE_DATE)
Values
(664, 22, TO_DATE (FEBRUARY 25, 2014 00:00:00 ',' DD/MM/YYYY HH24:MI:SS'), 'AIRPORT INTERNATIONAL ECONOMY' 26388.53, TO_DATE (MARCH 21, 2014 03:13:16 ',' DD/MM/YYYY HH24:MI:SS'));))
Insert into msidw. SHP_DW_TEMP_DEL_SPEND_TB
(CUSTOMER_ID, CARRIER_ID, BILL_DATE, SERVICE, COST, CREATE_DATE)
Values
(664, 22, TO_DATE (18 FEBRUARY 2014 00:00:00 ',' DD/MM/YYYY HH24:MI:SS'), 'AIRPORT INTERNATIONAL PRIORITY OVERNIGHT', TO_DATE 8825.98, (MARCH 21, 2014 03:13:16 ',' DD/MM/YYYY HH24:MI:SS'));))
Insert into msidw. SHP_DW_TEMP_DEL_SPEND_TB
(CUSTOMER_ID, CARRIER_ID, BILL_DATE, SERVICE, COST, CREATE_DATE)
Values
(664, 22, TO_DATE (4 FEBRUARY 2014 00:00:00 ',' DD/MM/YYYY HH24:MI:SS'), 'AIRPORT INTERNATIONAL ECONOMY' 31653.45, TO_DATE (MARCH 21, 2014 03:13:16 ',' DD/MM/YYYY HH24:MI:SS'));))
Insert into msidw. SHP_DW_TEMP_DEL_SPEND_TB
(CUSTOMER_ID, CARRIER_ID, BILL_DATE, SERVICE, COST, CREATE_DATE)
Values
(664, 22, TO_DATE (FEBRUARY 25, 2014 00:00:00 ',' DD/MM/YYYY HH24:MI:SS'), 'AIRPORT INTERNATIONAL PRIORITY OVERNIGHT', TO_DATE 7901.07, (MARCH 21, 2014 03:13:16 ',' DD/MM/YYYY HH24:MI:SS'));))
Insert into msidw. SHP_DW_TEMP_DEL_SPEND_TB
(CUSTOMER_ID, CARRIER_ID, BILL_DATE, SERVICE, COST, CREATE_DATE)
Values
(664, 22, TO_DATE (4 FEBRUARY 2014 00:00:00 ',' DD/MM/YYYY HH24:MI:SS'), 'AIRPORT INTERNATIONAL FEDEX GROUND', 167.73, TO_DATE (MARCH 21, 2014 03:13:16 ',' DD/MM/YYYY HH24:MI:SS'));))
Insert into msidw. SHP_DW_TEMP_DEL_SPEND_TB
(CUSTOMER_ID, CARRIER_ID, BILL_DATE, SERVICE, COST, CREATE_DATE)
Values
(664, 22, TO_DATE (18 FEBRUARY 2014 00:00:00 ',' DD/MM/YYYY HH24:MI:SS'), 'AIRPORT INTERNATIONAL FEDEX GROUND', 959.85, TO_DATE (MARCH 21, 2014 03:13:16 ',' DD/MM/YYYY HH24:MI:SS'));))
Insert into msidw. SHP_DW_TEMP_DEL_SPEND_TB
(CUSTOMER_ID, CARRIER_ID, BILL_DATE, SERVICE, COST, CREATE_DATE)
Values
(664, 22, TO_DATE (18 FEBRUARY 2014 00:00:00 ',' DD/MM/YYYY HH24:MI:SS'), 'AIRPORT INTERNATIONAL ECONOMY' 28209.22, TO_DATE (MARCH 21, 2014 03:13:16 ',' DD/MM/YYYY HH24:MI:SS'));))
COMMIT;
Insert into msidw.shp_dw_interm_tb
(java_session_id, user_id, customer_id, client_name, carrier_id, carrier_name, is_ltl_carrier, shipper_group_id, shipper_id, shipper_name, create_date, freight_rank)
Values
("E52AFB0183301775CD882C214A34F54F", 18686, 664, NULL, 22,)
"FedEx", 0, NULL, NULL, NULL,
TO_DATE('04/05/2014_00:00:00',_'MM/DD/YYYY_HH24:MI:SS'), 0);
Insert into msidw.shp_dw_interm_tb
(java_session_id, user_id, customer_id, client_name, carrier_id, carrier_name, is_ltl_carrier, shipper_group_id, shipper_id, shipper_name, create_date, freight_rank)
Values
("E52AFB0183301775CD882C214A34F54F", 18686, 664, NULL, 23,)
'DHL', 0, NULL, NULL, NULL,
TO_DATE('04/05/2014_00:00:00',_'MM/DD/YYYY_HH24:MI:SS'), 0);
Insert into msidw.shp_dw_interm_tb
(java_session_id, user_id, customer_id, client_name, carrier_id, carrier_name, is_ltl_carrier, shipper_group_id, shipper_id, shipper_name, create_date, freight_rank)
Values
("CA5AC1C5630D70B2E80E8E2A427DA249", 18686, 664, NULL, 21,)
'UPS', 0, NULL, NULL, NULL,
TO_DATE('04/05/2014_00:00:00',_'MM/DD/YYYY_HH24:MI:SS'), 0);
Insert into msidw.shp_dw_interm_tb
(java_session_id, user_id, customer_id, client_name, carrier_id, carrier_name, is_ltl_carrier, shipper_group_id, shipper_id, shipper_name, create_date, freight_rank)
Values
("CA5AC1C5630D70B2E80E8E2A427DA249", 18686, 664, NULL, 22,)
"FedEx", 0, NULL, NULL, NULL,
TO_DATE('04/05/2014_00:00:00',_'MM/DD/YYYY_HH24:MI:SS'), 0);
Insert into msidw.shp_dw_interm_tb
(java_session_id, user_id, customer_id, client_name, carrier_id, carrier_name, is_ltl_carrier, shipper_group_id, shipper_id, shipper_name, create_date, freight_rank)
Values
("CA5AC1C5630D70B2E80E8E2A427DA249", 18686, 664, NULL, 23,)
'DHL', 0, NULL, NULL, NULL,
TO_DATE('04/05/2014_00:00:00',_'MM/DD/YYYY_HH24:MI:SS'), 0);
Insert into msidw.shp_dw_interm_tb
(java_session_id, user_id, customer_id, client_name, carrier_id, carrier_name, is_ltl_carrier, shipper_group_id, shipper_id, shipper_name, create_date, freight_rank)
Values
("E52AFB0183301775CD882C214A34F54F", 18686, 664, NULL, 21,)
'UPS', 0, NULL, NULL, NULL,
TO_DATE('04/05/2014_00:00:00',_'MM/DD/YYYY_HH24:MI:SS'), 0);
COMMIT;
This is the query:
SELECT
DER_COST_PER_POUND_INTL_MONTH. BILL_DATE_M,
DER_COST_PER_POUND_INTL_MONTH. SERVICE,
DER_COST_PER_POUND_INTL_MONTH. WEIGHT,
DER_SPEND_BY_SERV_INTL_MONTHLY. COST
Of
(
SELECT CUSTOMER_ID, CARRIER_ID, to_char (SHP_DW_TEMP_DEL_WEIGHT_TB. BILL_DATE, 'MM - YY') as BILL_DATE_M,
(CASE
WHEN (LIKE '% GROUND INTERNATIONAL %' service
OR service LIKE '% INTERNATIONAL HOME DELIVERY %'
OR a service LIKE ' % international airport FEDEX GROUND-PRP %'
OR a service LIKE ' % international airport FEDEX GROUND-RTLABEL %'
OR a service LIKE '% international airport FEDEX GROUND %'
OR service LIKE ' % STANDARD.
OR service LIKE ' % worldwide %.
)
AND (NOT LIKE '% FEDEX INTL ECONOMY FRT %' service
AND service NOT LIKE ' % of the ECONOMY of FEDEX INTL.
"AND NOT AS service ' % airport % OF CARGO OF the ECONOMY".
"AND NOT AS service ' % airport % OF the ECONOMY.
AND NOT LIKE '% ECONOMY MAILSERVICE % INTL' service
AND NOT LIKE «% % ECONOMY» service
AND NOT LIKE '% FEDEX EXPRESS SAVER % INTL' service
AND NOT LIKE '% WW SAVER %' service
AND NOT LIKE '% CANADIAN % SAVER' service
AND NOT LIKE '% UPS SAVER %' service
AND NOT LIKE '% FEDEX INTL PRIORITY FRT %' service
AND NOT LIKE '% FEDEX INTL PRIORITY %' service
AND NOT LIKE '% MAILSERVICE INTL PRIORITY %' service
AND service NOT AS '% PRIORITY % PROPOSED international airport'
AND service NOT AS
'INTERNATIONAL PRIORITY DIRECTDISTRIBUTION % AIRPORT %'
AND service NOT LIKE '% ACCELERATED %.
AND service NOT AS ' % international airport 1 DAY FREIGHT %'
AND service NOT AS ' international airport FIRST NIGHT % %'
AND NOT AS '% FEDEX INTERNATIONAL FIRST' service
AND service NOT AS '% international airport MAILSERVICE-BONUS %'
AND service NOT AS '% UNKNOWN CODE % BASIC SERVICES international airport'
)
THEN "ground".
END
) service.
weight,
shipper_id
OF SHP_DW_TEMP_DEL_WEIGHT_TB
where
SHP_DW_TEMP_DEL_WEIGHT_TB. BILL_DATE > = trunc (add_months ((CASE WHEN sysdate < next_day (trunc (sysdate, 'MY')-1, 'MONDAY'), trunc(sysdate,'MON')-1 ELSE END sysdate), - 12), "MM") and SHP_DW_TEMP_DEL_WEIGHT_TB. BILL_DATE < trunc (last_day (add_months ((CASE WHEN sysdate < next_day (trunc (sysdate, 'MY')-1, 'MONDAY'), trunc(sysdate,'MON')-1 ELSE END sysdate), - 1)))
and extract (bill_date months) = 02
and customer_id = 664
GROUP BY
CARRIER_ID, CUSTOMER_ID, to_char (SHP_DW_TEMP_DEL_WEIGHT_TB. BILL_DATE, "MM - YY"), service, weight, SHIPPER_ID
) DER_COST_PER_POUND_INTL_MONTH,.
(
SELECT CUSTOMER_ID, CARRIER_ID, to_char (SHP_DW_TEMP_DEL_SPEND_TB. BILL_DATE, 'MM - YY') as BILL_DATE_M,
(CASE
WHEN (LIKE '% GROUND INTERNATIONAL %' service
OR service LIKE '% INTERNATIONAL HOME DELIVERY %'
OR a service LIKE ' % international airport FEDEX GROUND-PRP %'
OR a service LIKE ' % international airport FEDEX GROUND-RTLABEL %'
OR a service LIKE '% international airport FEDEX GROUND %'
OR service LIKE ' % STANDARD.
OR service LIKE ' % worldwide %.
)
AND (NOT LIKE '% FEDEX INTL ECONOMY FRT %' service
AND service NOT LIKE ' % of the ECONOMY of FEDEX INTL.
"AND NOT AS service ' % airport % OF CARGO OF the ECONOMY".
"AND NOT AS service ' % airport % OF the ECONOMY.
AND NOT LIKE '% ECONOMY MAILSERVICE % INTL' service
AND NOT LIKE «% % ECONOMY» service
AND NOT LIKE '% FEDEX EXPRESS SAVER % INTL' service
AND NOT LIKE '% WW SAVER %' service
AND NOT LIKE '% CANADIAN % SAVER' service
AND NOT LIKE '% UPS SAVER %' service
AND NOT LIKE '% FEDEX INTL PRIORITY FRT %' service
AND NOT LIKE '% FEDEX INTL PRIORITY %' service
AND NOT LIKE '% MAILSERVICE INTL PRIORITY %' service
AND service NOT AS '% PRIORITY % PROPOSED international airport'
AND service NOT AS
'INTERNATIONAL PRIORITY DIRECTDISTRIBUTION % AIRPORT %'
AND service NOT LIKE '% ACCELERATED %.
AND service NOT AS ' % international airport 1 DAY FREIGHT %'
AND service NOT AS ' international airport FIRST NIGHT % %'
AND NOT AS '% FEDEX INTERNATIONAL FIRST' service
AND service NOT AS '% international airport MAILSERVICE-BONUS %'
AND service NOT AS '% UNKNOWN CODE % BASIC SERVICES international airport'
)
THEN "ground".
END
) service.
COST,
SHIPPER_ID
OF SHP_DW_TEMP_DEL_SPEND_TB
where
SHP_DW_TEMP_DEL_SPEND_TB. BILL_DATE > = trunc (add_months ((CASE WHEN sysdate < next_day (trunc (sysdate, 'MY')-1, 'MONDAY'), trunc(sysdate,'MON')-1 ELSE END sysdate), - 12), "MM") and SHP_DW_TEMP_DEL_SPEND_TB. BILL_DATE < trunc (last_day (add_months ((CASE WHEN sysdate < next_day (trunc (sysdate, 'MY')-1, 'MONDAY'), trunc(sysdate,'MON')-1 ELSE END sysdate), - 1)))
and extract (bill_date months) = 02
and customer_id = 664
GROUP OF CUSTOMER_ID, CARRIER_ID, to_char (SHP_DW_TEMP_DEL_SPEND_TB. BILL_DATE, "MM - YY"), service, COST, SHIPPER_ID
) DER_SPEND_BY_SERV_INTL_MONTHLY,.
SHP_DW_INTERM_TB
WHERE
(NVL (DER_SPEND_BY_SERV_INTL_MONTHLY. CUSTOMER_ID,-1) = NVL (DER_COST_PER_POUND_INTL_MONTH. CUSTOMER_ID,-1))
AND (DER_SPEND_BY_SERV_INTL_MONTHLY. CARRIER_ID = DER_COST_PER_POUND_INTL_MONTH. CARRIER_ID)
AND (DER_SPEND_BY_SERV_INTL_MONTHLY. BILL_DATE_M = DER_COST_PER_POUND_INTL_MONTH. BILL_DATE_M)
AND (DER_SPEND_BY_SERV_INTL_MONTHLY. SERVICE = DER_COST_PER_POUND_INTL_MONTH. (SERVICE) - MNKB
AND (NVL (DER_SPEND_BY_SERV_INTL_MONTHLY. SHIPPER_ID,-1) = NVL (DER_COST_PER_POUND_INTL_MONTH. SHIPPER_ID,-1))
AND (NVL (SHP_DW_INTERM_TB. CUSTOMER_ID,-1) = NVL (DER_COST_PER_POUND_INTL_MONTH. CUSTOMER_ID,-1))
AND (SHP_DW_INTERM_TB. CARRIER_ID = DER_COST_PER_POUND_INTL_MONTH. CARRIER_ID)
AND (NVL (SHP_DW_INTERM_TB. SHIPPER_ID,-1) = NVL (DER_COST_PER_POUND_INTL_MONTH. SHIPPER_ID,-1))
AND
(
SHP_DW_INTERM_TB. JAVA_SESSION_ID in ('CA5AC1C5630D70B2E80E8E2A427DA249')
AND
SHP_DW_INTERM_TB. User_id in (18686)
AND
SHP_DW_INTERM_TB.IS_LTL_CARRIER (0)
)
GROUP BY
DER_COST_PER_POUND_INTL_MONTH. BILL_DATE_M,
DER_COST_PER_POUND_INTL_MONTH. WEIGHT,
DER_SPEND_BY_SERV_INTL_MONTHLY. COST,
DER_COST_PER_POUND_INTL_MONTH. SERVICE
order of DER_COST_PER_POUND_INTL_MONTH.service
The result I want is
Billing date Service Weight Cost 04/02/14 On the ground 121 167.73 11/02/14 On the ground 243 181.19 18/02/2014 On the ground 729 959.85 25/02/2014 On the ground 602 356.65 The above query gives each weight mapped to each cost, so the resulting values are summarizing to greater value than the above expected values.
Can someone help me please how do I change my request to get my desired result.
Kind regards
Mr Kishore N. badin.
SELECT DER_COST_PER_POUND_INTL_MONTH. BILL_DATE_M,
DER_COST_PER_POUND_INTL_MONTH. SERVICE,
DER_COST_PER_POUND_INTL_MONTH. WEIGHT,
DER_SPEND_BY_SERV_INTL_MONTHLY. COST
IN (SELECT CUSTOMER_ID,
CARRIER_ID,
TO_CHAR (SHP_DW_TEMP_DEL_WEIGHT_TB. BILL_DATE, 'DD-MM-YY') as BILL_DATE_M,
BOX WHEN (LIKE '% GROUND INTERNATIONAL %' service
OR service LIKE '% INTERNATIONAL HOME DELIVERY %'
OR a service LIKE ' % international airport FEDEX GROUND-PRP %'
OR a service LIKE ' % international airport FEDEX GROUND-RTLABEL %'
OR a service LIKE '% international airport FEDEX GROUND %'
OR service LIKE ' % STANDARD.
OR service LIKE ' % worldwide %.
)
AND (NOT LIKE '% FEDEX INTL ECONOMY FRT %' service
AND service NOT LIKE ' % of the ECONOMY of FEDEX INTL.
"AND NOT AS service ' % airport % OF CARGO OF the ECONOMY".
"AND NOT AS service ' % airport % OF the ECONOMY.
AND NOT LIKE '% ECONOMY MAILSERVICE % INTL' service
AND NOT LIKE «% % ECONOMY» service
AND NOT LIKE '% FEDEX EXPRESS SAVER % INTL' service
AND NOT LIKE '% WW SAVER %' service
AND NOT LIKE '% CANADIAN % SAVER' service
AND NOT LIKE '% UPS SAVER %' service
AND NOT LIKE '% FEDEX INTL PRIORITY FRT %' service
AND NOT LIKE '% FEDEX INTL PRIORITY %' service
AND NOT LIKE '% MAILSERVICE INTL PRIORITY %' service
AND service NOT AS '% PRIORITY % PROPOSED international airport'
AND service NOT AS '% airport international PRIORITY DIRECTDISTRIBUTION %'
AND service NOT LIKE '% ACCELERATED %.
AND service NOT AS ' % international airport 1 DAY FREIGHT %'
AND service NOT AS ' international airport FIRST NIGHT % %'
AND NOT AS '% FEDEX INTERNATIONAL FIRST' service
AND service NOT AS '% international airport MAILSERVICE-BONUS %'
AND service NOT AS '% UNKNOWN CODE % BASIC SERVICES international airport'
)
THEN "ground".
END of service,
weight,
shipper_id
OF SHP_DW_TEMP_DEL_WEIGHT_TB
where SHP_DW_TEMP_DEL_WEIGHT_TB. BILL_DATE > =.
trunc (add_months (BOX WHEN sysdate< next_day(trunc(sysdate,'mon')="" -="">
'MONDAY '.
)
THEN trunc (sysdate, 'MY') - 1
Of ANOTHER sysdate
END,
-12
),
"MM".
)
and SHP_DW_TEMP_DEL_WEIGHT_TB. BILL_DATE
trunc (last_day (add_months (BOX WHEN sysdate< next_day(trunc(sysdate,'mon')="" -="">
'MONDAY '.
)
THEN trunc (sysdate, 'MY') - 1
Of ANOTHER sysdate
END,
-1
)
)
)
and extract (bill_date months) = 02
and customer_id = 664
GROUP CARRIER_ID,
CUSTOMER_ID,
TO_CHAR (SHP_DW_TEMP_DEL_WEIGHT_TB. BILL_DATE, 'DD-MM-YY'),
service, weight, SHIPPER_ID
) DER_COST_PER_POUND_INTL_MONTH,.
(SELECT CUSTOMER_ID,
CARRIER_ID,
TO_CHAR (SHP_DW_TEMP_DEL_SPEND_TB. BILL_DATE, 'DD-MM-YY') as BILL_DATE_M,
BOX WHEN (LIKE '% GROUND INTERNATIONAL %' service
OR service LIKE '% INTERNATIONAL HOME DELIVERY %'
OR a service LIKE ' % international airport FEDEX GROUND-PRP %'
OR a service LIKE ' % international airport FEDEX GROUND-RTLABEL %'
OR a service LIKE '% international airport FEDEX GROUND %'
OR service LIKE ' % STANDARD.
OR service LIKE ' % worldwide %.
)
AND (NOT LIKE '% FEDEX INTL ECONOMY FRT %' service
AND service NOT LIKE ' % of the ECONOMY of FEDEX INTL.
"AND NOT AS service ' % airport % OF CARGO OF the ECONOMY".
"AND NOT AS service ' % airport % OF the ECONOMY.
AND NOT LIKE '% ECONOMY MAILSERVICE % INTL' service
AND NOT LIKE «% % ECONOMY» service
AND NOT LIKE '% FEDEX EXPRESS SAVER % INTL' service
AND NOT LIKE '% WW SAVER %' service
AND NOT LIKE '% CANADIAN % SAVER' service
AND NOT LIKE '% UPS SAVER %' service
AND NOT LIKE '% FEDEX INTL PRIORITY FRT %' service
AND NOT LIKE '% FEDEX INTL PRIORITY %' service
AND NOT LIKE '% MAILSERVICE INTL PRIORITY %' service
AND service NOT AS '% PRIORITY % PROPOSED international airport'
AND service NOT AS '% airport international PRIORITY DIRECTDISTRIBUTION %'
AND service NOT LIKE '% ACCELERATED %.
AND service NOT AS ' % international airport 1 DAY FREIGHT %'
AND service NOT AS ' international airport FIRST NIGHT % %'
AND NOT AS '% FEDEX INTERNATIONAL FIRST' service
AND service NOT AS '% international airport MAILSERVICE-BONUS %'
AND service NOT AS '% UNKNOWN CODE % BASIC SERVICES international airport'
)
THEN "ground".
END of service,
COST,
SHIPPER_ID
OF SHP_DW_TEMP_DEL_SPEND_TB
where SHP_DW_TEMP_DEL_SPEND_TB. BILL_DATE > =.
trunc (add_months (BOX WHEN sysdate< next_day(trunc(sysdate,'mon')="" -="">
'MONDAY '.
)
THEN trunc (sysdate, 'MY') - 1
Of ANOTHER sysdate
END,
-12
),
"MM".
)
and SHP_DW_TEMP_DEL_SPEND_TB. BILL_DATE
trunc (last_day (add_months (BOX WHEN sysdate< next_day(trunc(sysdate,'mon')="" -="">
'MONDAY '.
)
THEN trunc(sysdate,'MON')-1
Of ANOTHER sysdate
END,
-1
)
)
)
and extract (bill_date months) = 02
and customer_id = 664
CUSTOMER_ID GROUP,
CARRIER_ID,
TO_CHAR (SHP_DW_TEMP_DEL_SPEND_TB. BILL_DATE, 'DD-MM-YY'),
service, COST, of SHIPPER_ID
) DER_SPEND_BY_SERV_INTL_MONTHLY,.
SHP_DW_INTERM_TB
WHERE (NVL (DER_SPEND_BY_SERV_INTL_MONTHLY. CUSTOMER_ID,-1) = NVL (DER_COST_PER_POUND_INTL_MONTH. CUSTOMER_ID,-1))
AND (DER_SPEND_BY_SERV_INTL_MONTHLY. CARRIER_ID = DER_COST_PER_POUND_INTL_MONTH. CARRIER_ID)
AND (DER_SPEND_BY_SERV_INTL_MONTHLY. BILL_DATE_M = DER_COST_PER_POUND_INTL_MONTH. BILL_DATE_M)
AND (DER_SPEND_BY_SERV_INTL_MONTHLY. SERVICE = DER_COST_PER_POUND_INTL_MONTH. (SERVICE) - MNKB
AND (NVL (DER_SPEND_BY_SERV_INTL_MONTHLY. SHIPPER_ID,-1) = NVL (DER_COST_PER_POUND_INTL_MONTH. SHIPPER_ID,-1))
AND (NVL (SHP_DW_INTERM_TB. CUSTOMER_ID,-1) = NVL (DER_COST_PER_POUND_INTL_MONTH. CUSTOMER_ID,-1))
AND (SHP_DW_INTERM_TB. CARRIER_ID = DER_COST_PER_POUND_INTL_MONTH. CARRIER_ID)
AND (NVL (SHP_DW_INTERM_TB. SHIPPER_ID,-1) = NVL (DER_COST_PER_POUND_INTL_MONTH. SHIPPER_ID,-1))
AND (SHP_DW_INTERM_TB. JAVA_SESSION_ID in ('CA5AC1C5630D70B2E80E8E2A427DA249')
AND SHP_DW_INTERM_TB. User_id in (18686)
AND SHP_DW_INTERM_TB.IS_LTL_CARRIER (0)
)
GROUP OF DER_COST_PER_POUND_INTL_MONTH. BILL_DATE_M,
DER_COST_PER_POUND_INTL_MONTH. WEIGHT,
DER_SPEND_BY_SERV_INTL_MONTHLY. COST,
DER_COST_PER_POUND_INTL_MONTH. SERVICE
order DER_COST_PER_POUND_INTL_MONTH. BILL_DATE_M, DER_COST_PER_POUND_INTL_MONTH.service
BILL_DATE_M SERVICE WEIGHT COST 02/04/14 On the ground 121 167.73 02/11/14 On the ground 243 181.19 18/02/14 On the ground 729 959.85 25/02/14 On the ground 602 356.65 Concerning
Etbin
-
Return summary for the masters of query classes
Hi all
I use oracle database 11g r2.
I have 2 tables,
create tabel expenses_heads (exp_head_id number primary key, Main_exp_name varchar2(100) not null, refer_exp_head_id number); alter table expenses_heads add constraint fk_refer_head_id foreign key(refer_exp_id) references expenses_heads(exp_head_id); create table expenses (exp_id number primary key, exp_head_id number references expenses_heads(exp_head_id) not null, exp_name varchar2(100) not null, exp_date date not null, exp_amount number not null, receipt varchar2(20), remarks varchar2(4000)); i have the following data, insert into expenses_heads values(1,'School',null); insert into expenses_heads values(2,'College',null); insert into expenses_heads values(3,'Bills',1); insert into expenses_heads values(4,'Hardware',1); insert into expenses_heads values(5,'Food',1); insert into expenses_heads values(6,'Dress',1); insert into expenses_heads values(7,'Hardware',1); insert into expenses_heads values(8,'Admission',2); insert into expenses_heads values(9,'Office',2); insert into expenses values(1,3,'Electricity Bill',sysdate,1000,null,null); insert into expenses values(2,3,'Water Bill',sysdate,100,null,null); insert into expenses values(3,4,'Chair',sysdate,1000,null,null); insert into expenses values(4,4,'Tables',sysdate,200,null,null); insert into expenses values(5,8,'Admin Ceremony',sysdate,3000,null,null); insert into expenses values(6,9,'Stationary',sysdate,2000,null,null); commit;
now, I want to write a query relating analytical columns, Main_exp_name(from expenses_heads) and Total_amount (from expenses)
result should look as below
Main_exp_name Total_Amount College 2300 university 5000
I think it could be written using the Group of and rollup, cube or grouping sets, but confused.
kindly help.
Hierarchical query using:
select h.main_exp_name, sum (exp_amount) exp_amount from expenses e join ( select refer_exp_id, exp_head_id, prior main_exp_name main_exp_name from expenses_heads connect by refer_exp_id = prior exp_head_id ) h on ( e.exp_head_id = h.exp_head_id ) where main_exp_name is not null group by h.main_exp_name; MAIN_EXP_NAME EXP_AMOUNT ---------------------------------------------------------------------------------------------------- ---------------------- School 2300 College 5000
-
In summary for two different periods - 1 query?
Hello
To find budgetary changes to a project within a range of periods, I select the type of Budget records, get the settings "until the" and calculate the difference between the project_to_date_dr - project_to_date_cr of the tip and the FromDate. (I use the gl_balances twice in the query under two pseudonyms).
Do this in a query and the data that I checked are correct.
When I want to do the same for the load, it becomes problematic. My understanding is that in the calculation of the load, I need to know the difference between the SUM of the project_to_date_dr and the SUM... cr of dates. What happens is, since there are two rows in the example, I test, I don't get the charge but double the load.
The (shortened) query:
Select (sum (nvl(glb_ToDate.project_to_date_dr,0))-
Sum (NVL(glb_ToDate.project_to_date_cr,0))
) -
(sum (nvl(glb_FromDate.project_to_date_dr,0))-
Sum (NVL(glb_FromDate.project_to_date_cr,0))
) CCID_Encumbrance
of gl.gl_balances glb_ToDate,.
GL.gl_balances glb_FromDate
where
glb_FromDate.Code_Combination_Id = glb_ToDate.Code_Combination_Id and
glb_ToDate.set_of_books_id = 1 and
glb_ToDate.currency_code = "USD" and
glb_ToDate.actual_flag = 'E' and
glb_FromDate.set_of_books_id = 1 and
glb_FromDate.currency_code = "USD" and
glb_FromDate.actual_flag = 'E' and
glb_ToDate.Period_Name = ' 03-2010 "and
glb_FromDate.Period_Name = ' 01-2010"and
glb_FromDate.Code_Combination_Id = 442719
Glb_FromDate.Code_Combination_Id group,
glb_ToDate.Code_Combination_Id
The result of the load is 199,68.
If I remove the "sum" and "group by", I get four rows - two with an amount of 0 and two with a $ 99.84.
I have to build two separate queries/sub-sub-queries and then combine them?
Thank you.
LeahYou must use both hands and combine.
Maybe you are looking for
-
End of 2012 very slow Mac. Etrecheck joint
I have a Mac to end 2012, El Capitan, which has been gradually running slower and slower. It seems preferable, once he is fully initialized, but it takes that which feels like an age to actually start, and if I try to open applications such as Mail,
-
Several Internet gel 30 seconds + DDoS attacks
I get anywhere from 3 to 10 per day ddos attacks, many of them coming from the same IP it happens every day and it's really annoying. I tried to install some VPN and DDoS protection free programs, with no help. These 3-15 attacks, I have to deal with
-
HP 15-AC042TU: Windows 7 (64 bit) drivers for my laptop model HP 15-AC042TU
Hi everyone, I just bought Hp 15-AC042TU and installed win7 64 bit. I tried to find the drivers but could not achieve, please help me. Thank you.
-
How can I create multidimensional arrays of controls?
I build a VI that will have hundreds of power keys, 24 on each of the 8 tabs. I can deal with them programmatically in an array, like this: and to find one that was pushed with some XOR'ing: But what happens if I want two rows of 12 buttons? I can
-
Cannot start programs - OPEN WITH missing function
A few days ago, I tried to download and install a chess in Chessbase engine, a database utility. I did not. I remember at one point a flashing horizontal line in the upper left corner of a window black arise at a time, so that illuminates what could