Help required with SQL query
I have three tables listed belowFORMAT - Columns are format_id, format_desc
VIDEO_FORMAT - areVIDEO_FORMAT_ID of columns, COST VIDEO_ID, FORMAT_ID,
RENTAL - Coulmns are RENTAL_ID, DATE_OUT, DATE_DUE, DATE_IN, DELIVERY_STATUS, LATE_FEE, CUSTOMER_ID, VIDEO_FORMAT_ID
I need to find the customer list id, format description and cost of the video format for customers who have rented a video.
I wrote the request
Select rental r format f, video_format, r.customer_id, f.format_desc, vf.cost vf where f.format_id in (select video_format format_id) and r.video_format_id = vf.video_format_id
This isn't to get accurate results. Help, please.
Would know what kind of results you get, but I think that I can see.
Try:
Select r.customer_id, f.format_desc, vf.cost
rental r, f format, video_format vf
where vf.format_id = f.format_id
and r.video_format_id = vf.video_format_id
Can't be sure without a little more information so that will set you. But I do not know why you went with trying to get a relationship using an IN with a subquery. It will be useful.
Tags: Database
Similar Questions
-
Help me with SQL Query to retrieve data from a view
Hello Guru,
I need help in my sql query.
I use SQL TeraData.
I want an Oracle result in the following form-
Open tickets
Open months failure / Repair Service s/o improvement request Total general
2009-01-2 4 4 5 15
2009-02 1 0 2 3 6
2009-03 4 1 2 2 9
Grand Total 7 5 8 10 30
I wrote the query as where - TIME_PERIOD, RQST_TYPE_DM and DEMAND_SUMMARY_FCT are the points of view and I extract the data from the views only.
Select NVL (CA. TIME_PERIOD. PERIOD_CD, 'Total') THAT year.
COUNT (CASE WHEN CA. RQST_TYPE_DM. RQSTTYP_DESC Like '% of Break' THEN 1 END) as BreakFix
COUNT (CASE WHEN CA. RQST_TYPE_DM. RQSTTYP_DESC as 'N/a', 1 END) by n/a
COUNT (CASE WHEN CA. RQST_TYPE_DM. RQSTTYP_DESC as 'Improvement' THEN 1 END) accessories
COUNT (CASE WHEN CA. RQST_TYPE_DM. RQSTTYP_DESC Like '% Service' THEN 1 END) as ServiceRequests
COUNT (CA. RQST_TYPE_DM. RQSTTYP_DESC) AS grand_total
FROM CA. TIME_PERIOD, CA. RQST_TYPE_DM, CA. DEMAND_SUMMARY_FCT
WHERE (CA. DEMAND_SUMMARY_FCT. RQSTTYP_ID = CA. RQST_TYPE_DM. RQSTTYP_ID)
AND (CASE
WHEN CA. DEMAND_SUMMARY_FCT. MONTH_ID = CA. TIME_PERIOD. PERIOD_ID, 1
WHEN {fn concat ({fn concat (SUBSTR (CA. TIME_PERIOD. {(PERIOD_CD, 3, 4),'-')}, SUBSTR (CA. TIME_PERIOD. PERIOD_CD, 7, 2))} BETWEEN ' 2009-01' AND ' 2009-03' THEN 1
WHEN CA. DEMAND_SUMMARY_FCT. RQSTTYP_ID = '1' then 1
END) = 1
GROUP BY ROLLUP (CA. TIME_PERIOD. PERIOD_CD)
After executing the query, I get the following error:
3076: syntax Error: Data Type 'Time' does not match a defined Type name.
:( Kindly help me with this and let me know where I'm wrong... Please.Messages indicates something wrong with your data... It would seem that the data does not match your format mask.
Thus, the data or the format mask.
-
I have a table and passes as below:
START DATE TOTAL NUMBER OF DAYS
11/10/2011 15:00 1
15/10/2011-05:00 1
2011-12-22 10:00 1
22/12/2011 11:00 2
30/12/2011-10:00 1
01/01/2012 01:00 1
01/01/2012 10:00 1
01/01/2012 16:00 2
02/01/2012 14:00 1
03/01/2012-15:00 1
04/01/2012-15:00 2
04/01/2012 18:00 1
I need to ask where the values in the table above
must return values as below:
I tried many ways, but not able to find the solution.
Kindly help me in this regard.
START DATE TOTAL NUMBER OF DAYS
11/10/2011 15:00 1
15/10/2011-05:00 1
22/12/2011 11:00 2
30/12/2011-10:00 1
01/01/2012 16:00 2
02/01/2012 14:00 1
03/01/2012-15:00 1
04/01/2012-15:00 2
the ultimate goal is to summarize the TOTAL number of DAYS column all the numbers in the second table... All jobs must be treated in the same query. I can't use the coding of java to process what my requirement should be included in the query that already exists.
Published by: 915175 on February 16, 2012 23:02select trunc(start_date), max(start_date), max(total_days) from tablename group by trunc(start_date);
Please check below is on my local site with you Test data:
SQL> SQL> with tablename as 2 ( 3 select to_date('10/11/2011 15:00' , 'mm/dd/yyyy hh24:mi') start_date, 1 total_days from dual union all 4 select to_date('10/15/2011 5:00' , 'mm/dd/yyyy hh24:mi') start_date, 1 total_days from dual union all 5 select to_date('12/22/2011 10:00' , 'mm/dd/yyyy hh24:mi') start_date, 1 total_days from dual union all 6 select to_date('12/22/2011 11:00' , 'mm/dd/yyyy hh24:mi') start_date, 2 total_days from dual union all 7 select to_date('12/30/2011 10:00' , 'mm/dd/yyyy hh24:mi') start_date, 1 total_days from dual union all 8 select to_date('1/1/2012 1:00' , 'mm/dd/yyyy hh24:mi') start_date, 1 total_days from dual union all 9 select to_date('1/1/2012 10:00' , 'mm/dd/yyyy hh24:mi') start_date, 1 total_days from dual union all 10 select to_date('1/1/2012 16:00' , 'mm/dd/yyyy hh24:mi') start_date, 2 total_days from dual union all 11 select to_date('1/2/2012 14:00' , 'mm/dd/yyyy hh24:mi') start_date, 1 total_days from dual union all 12 select to_date('1/3/2012 15:00' , 'mm/dd/yyyy hh24:mi') start_date, 1 total_days from dual union all 13 select to_date('1/4/2012 15:00' , 'mm/dd/yyyy hh24:mi') start_date, 2 total_days from dual union all 14 select to_date('1/4/2012 18:00' , 'mm/dd/yyyy hh24:mi') start_date, 1 total_days from dual 15 ) 16 select TO_CHAR(max(start_date),'MM/DD/YYYY HH24:MI') start_date , max(total_days) total_days from tablename 17 group by trunc(start_date); START_DATE TOTAL_DAYS ---------------- ---------- 10/15/2011 05:00 1 01/03/2012 15:00 1 12/30/2011 10:00 1 01/01/2012 16:00 2 10/11/2011 15:00 1 12/22/2011 11:00 2 01/04/2012 18:00 2 01/02/2012 14:00 1 8 rows selected. SQL>
Kind regards
Lifexisxnotxsoxbeautiful...Update: added test done to my database...
Edited by: lifexisxnotxsoxbeautiful Vithalani, on February 16, 2012 23:18
-
Hello
I have data like shown below:
ID DATE NUM_PCT
1 June 1, 2011 1.2
1-2 June 2011 NULL
1-3 June 2011 NULL
1 6 June 2011 NULL
1 July 1, 2011 1.25
1 NULL July 4, 2011
2 June 1, 2011 1.3
2 NULL June 2, 2011
2-3 June 2011 NULL
2 June 6, 2011 1.29
2 NULL June 7, 2011
2 NULL 8 June 2011
2 June 9, 2011 1.31
2 NULL 10 June 2011
and I want to convert the data as shown below:
ID DATE NUM_PCT
1 June 1, 2011 1.2
1 June 2, 2011 1.2
1 1.2 3 June 2011
1 June 6, 2011 1.2
1 July 1, 2011 1.25
1 July 4, 2011 1.25
2 June 1, 2011 1.3
2 June 2, 2011 1.3
2 June 3, 2011 1.3
2 June 6, 2011 1.29
2 June 7, 2011 1.29
2 June 8, 2011 1.29
2 June 9, 2011 1.31
2 June 10, 2011 1.31
I use Oracle 10.2.0.4.0
Please help me in writing a request for it.with t as ( select 1 id,to_date('01-Jun-2011','dd-mon-yyyy') dt,1.2 num_pct from dual union all select 1,to_date('02-Jun-2011','dd-mon-yyyy'),NULL from dual union all select 1,to_date('03-Jun-2011','dd-mon-yyyy'),NULL from dual union all select 1,to_date('06-Jun-2011','dd-mon-yyyy'),NULL from dual union all select 1,to_date('01-Jul-2011','dd-mon-yyyy'),1.25 from dual union all select 1,to_date('04-Jul-2011','dd-mon-yyyy'),NULL from dual union all select 2,to_date('01-Jun-2011','dd-mon-yyyy'),1.3 from dual union all select 2,to_date('02-Jun-2011','dd-mon-yyyy'),NULL from dual union all select 2,to_date('03-Jun-2011','dd-mon-yyyy'),NULL from dual union all select 2,to_date('06-Jun-2011','dd-mon-yyyy'),1.29 from dual union all select 2,to_date('07-Jun-2011','dd-mon-yyyy'),NULL from dual union all select 2,to_date('08-Jun-2011','dd-mon-yyyy'),NULL from dual union all select 2,to_date('09-Jun-2011','dd-mon-yyyy'),1.31 from dual union all select 2,to_date('10-Jun-2011','dd-mon-yyyy'),NULL from dual ) -- end of on-the-fly data sample select id, dt, last_value(num_pct ignore nulls) over(partition by id order by dt) num_pct from t order by id, dt / ID DT NUM_PCT ---------- --------- ---------- 1 01-JUN-11 1.2 1 02-JUN-11 1.2 1 03-JUN-11 1.2 1 06-JUN-11 1.2 1 01-JUL-11 1.25 1 04-JUL-11 1.25 2 01-JUN-11 1.3 2 02-JUN-11 1.3 2 03-JUN-11 1.3 2 06-JUN-11 1.29 2 07-JUN-11 1.29 ID DT NUM_PCT ---------- --------- ---------- 2 08-JUN-11 1.29 2 09-JUN-11 1.31 2 10-JUN-11 1.31 14 rows selected. SQL>
SY.
-
Hello
Please help build a sql query
My Table Test2015 has given belowHeader_id Line_id Ordered_item
723887290 199925 MAIN1
199925 723887291 MAIN2
199926 723887292 SH-POS-NO-BR POS-INS
199926 723887293 MAIN2
199927 723887294 IC-ENV-NON-BR-ENV-PXY
199927 723887295 MAIN1
199927 723887297 MAIN2
199927 723887298 PRCSS SH-FAIRY-ELEC DISTR.
199927 723887299 SH-FAIRY-SUM PRO-DE-CONS-HOUSE
I am trying to query my Test2015 table to obtain the records with ordered_item containing 'MAIN1' and 'MAIN2' only. I tried to write a query as below
SELECT * FROM test2015 WHERE ORDERED_ITEM in ('MAIN1', 'MAIN2');
But it gives me all the data with the MAIN2 records found but MAIN1 is absent, I want to retrieve only records to both 'MAIN1' and 'MAIN2' present for Header_id.
While the result below shows me header_id - 199926 and 199929 that he should assume back. I want to fetch documents only with 'MAIN1' and 'MAIN2' both present.
Header_id Line_id Ordered_item
723887290 199925 MAIN1
199925 723887291 MAIN2
199926 723887293 MAIN2
199927 723887295 MAIN1
199927 723887297 MAIN2
199929 723887299 MAIN1
Please suggest.
Thank you and best regards,
Prasad.
Hello
Try like this...
SELECT * FROM test2015 WHERE ORDERED_ITEM in ('MAIN1") and in header_id (select test2015 WHERE ORDERED_ITEM in ('MAIN2') header_id)
-
Help with SQL Query (Subselects)
Hello community,
IAM a new Member in this forum. The first excuse my English, my native language is German.
In my workplace, we have a great Orcle Database 11 g with 30 different tables for production control issues.
I try to get a couple of different information from the database, so I started with SQL of the query, but for this problem, I wasn't able to write a query to work.
In this case, I have 2 tables:
Table 1:
ID; ORDER_NR; DESCRIPTION; CREATE_DATE
1; A500236; CLEAN HOUSE; 20/02/2012
2; A623555; REPAIR CAR; 10/01/2012
3; A866944; MAINTAIN EQUIPMENT; 11/02/2012
Table 2:
ID; ORDER_NR; WO_STEP; STEP_DATE; EMPLOYEE
1; A500236; A; 21/02/2012; W0010
2; A500239; F; 21/02/2012; W0010
3; A500239; S; 22/02/2012; W0027
4; A500239; R; 23/02/2012; H0034
5; A500239; U; 25/02/2012; L0099
6; A263555; A; 15/01/2012; G0009
7; A263555; C; 17/01/2012; S0039
5 V A263555; R; 18/01/2012; K0059
9; A263555; U; 19/01/2012; A0048
10; A866944; A; 13/02/2012; H0034
11; A866944; B; 13/02/2012; L0035
12; A866944; G; 17/02/2012; D0084
13; A866944; U; 23/02/2012; S0039
And the result of my query should look like this:
ORDER_NR; DESCRIPTION; CREATE_DATE; A_STAT_AGE; R_STAT_AGE; U_STAT_AGE
A500236; OWN HOME; 20/02/2012; 5; 3; 1
A623555; REPAIR CAR; 01/10/2012; 42; 39; 38
A866944; MAINTAIN EQUIPMENT; 11/02/2012; 15; 4; 3
The age of my query result should be calculated from the date of the creation of the order.
I would like to know 2 things, one is how old was the order when they reached this status, R and U.
The second, that is, how long did you order remaining on A stat, R and U (and if possible all the others too)
It can happen that not every order reaches every State, so he ca go directly from A you in this case I want to display a generic character in this row/column
I hope you all know what I mean and what result to expect.
Thanks for your help.
Reinhard W.Hi, Reinhard,
990524 wrote:
Hi Frank,.I thank you for your professional response and excuse my non-professional way to clarify my question.
I have now already read and understand how to ask good questions, but is there an easy an inexpensive way to run a database on my computer at home?You can download the Oracle database from this site. The Express edition is easier to install. It lacks a few features that the Enterprise edition (for example, partitioning table and safety of level line), but most of the things work in all editions of Oracle.
All editions are free if you do not use them for Production applications. Of course, at this price (or lack thereof), you get Oracle support.I have already noticed that the syntax SQL for Oracle differ from other DBMSS.
Yes and some features are different in different products.
Your query works perfectly, thank you.
Now I want to refine my (your) query, is there a way to display a range of day within 1 day? As 0.5 day to half a day between two State timestamp.
Of course, you can do it. After the exact output desired of the sample data that I posted. If the sample data do not show what you need to do, then after a few different examples of data that makes.
My table contains the Date and time in a row, I forgot to mention that.
After a CREATE TABLE statement. I was guessing a lot of things that may be important. For example, I assumed you were using a DATE for date and time column. So it is only reasonable to do so, but maybe it's not what looks like at your table.
I tried something like this:
SYSDATE - MIN ( CASE WHEN t2.wo_step = 'A' THEN t2.step_date END ) AS Age_A
But it gives me an error of arithmetic overflow and not die difference in the Date and time or days with decimal friction.
There are only about 5.4 million possible days with DATEs of Oracle. Is only 7 digits and Oracle can treat approximately 39 numbers without overflow errors, so I don't see how this can happen if t2.step_date is really a DATE. This is an example of why you need to publish a CREATE TABLE statement.
-
Help with SQL query definition
Hello
Could someone please help me with the sub condition.
On the example of the EMP table, I want a report that looks like:
Please see the application for the relevant columns and the definitions of the watch below:Manager Tot_Joiniees_Q1 Tot_Joiniees_Q2 Tot_Joiniees_Q3 Tot_Joiniees_Q4
Thank youSELECT mgr, CASE WHEN TO_CHAR (hiredate, 'MON') IN ('JUN', 'JUL', 'AUG') THEN 'Q1' WHEN TO_CHAR (hiredate, 'MON') IN ('SEP', 'OCT', 'NOV') THEN 'Q2' WHEN TO_CHAR (hiredate, 'MON') IN ('DEC', 'JAN', 'FEB') THEN 'Q3' WHEN TO_CHAR (hiredate, 'MON') IN ('MAR', 'APR', 'MAY') THEN 'Q4' END qtd, COUNT (DISTINCT ename) FROM emp GROUP BY mgr, CASE WHEN TO_CHAR (hiredate, 'MON') IN ('JUN', 'JUL', 'AUG') THEN 'Q1' WHEN TO_CHAR (hiredate, 'MON') IN ('SEP', 'OCT', 'NOV') THEN 'Q2' WHEN TO_CHAR (hiredate, 'MON') IN ('DEC', 'JAN', 'FEB') THEN 'Q3' WHEN TO_CHAR (hiredate, 'MON') IN ('MAR', 'APR', 'MAY') THEN 'Q4' END ORDER BY 1, 2
CJMSELECT mgr Manager, COUNT(CASE WHEN TO_CHAR(hiredate,'Q') = '1' then 1 end) Tot_Joiniees_Q1, COUNT(CASE WHEN TO_CHAR(hiredate,'Q') = '2' then 1 end) Tot_Joiniees_Q2, COUNT(CASE WHEN TO_CHAR(hiredate,'Q') = '3' then 1 end) Tot_Joiniees_Q3, COUNT(CASE WHEN TO_CHAR(hiredate,'Q') = '4' then 1 end) Tot_Joiniees_Q4 FROM emp GROUP BY mgr, TO_CHAR(hiredate,'Q') / MANAGER TOT_JOINIEES_Q1 TOT_JOINIEES_Q2 TOT_JOINIEES_Q3 TOT_JOINIEES_Q4 ---------- --------------- --------------- --------------- --------------- 7566 0 0 0 1 7839 0 3 0 0 7698 0 0 2 0 7788 0 1 0 0 7782 1 0 0 0 7566 0 1 0 0 7902 0 0 0 1 7698 2 0 0 0 0 0 0 1 7698 0 0 0 1 10 rows selected. SQL>
SY.
-
need help with sql query dates
Hello
I have a sql query I need to extract some info between data dates. Where clause in this query is:
WHERE CPD_BUS_UNIT =: ESI_PRM_1
AND CPD_VOUCHER_DATE > =: P_DATE_FROM
AND CPD_VOUCHER_DATE < (: P_DATE_TO + 1).
When I run the query into a toad, I can view the data, but not the execution plan. It gives an error ORA-00932 inconsistent Datatypes.
But when I remove (+ 1): P_DATE_TO, I can c the execution plan and data. The data will be different from the previous.
Please suggest how to rewrite the query.Can you please give it a try?
WHERE CPD_BUS_UNIT=:ESI_PRM_1 AND CPD_VOUCHER_DATE >= :to_date(P_DATE_FROM) AND CPD_VOUCHER_DATE < (to_date(:P_DATE_TO)+1)
Concerning
-
Hello
It's my first table REPORT
report as)
Select 'vendor_1' vendor, to_date('1/1/2012','DD/MM/YYYY') supply_date, "customer_1" as a customer, "item_1" like item1, 110 as cost of double union all
Select 'vendor_1' vendor, to_date('1/3/2012','MM/DD/YYYY') supply_date, "customer_1" as a customer, "item_1" like item1, 120 as cost of double union all
Select 'vendor_1' vendor, to_date('1/3/2012','MM/DD/YYYY') supply_date, "customer_1" as a customer, "item_1" like item1, 130 as cost of double union all
Select 'vendor_1' vendor, to_date('1/4/2012','MM/DD/YYYY') supply_date, "customer_1" as a customer, "item_1" like item1, 140 as cost of double union all
Select 'vendor_1' vendor, to_date('1/10/2012','MM/DD/YYYY') supply_date, "customer_1" as a customer, "item_1" element, 200as cost of double union all
Select 'vendor_1' vendor, to_date('1/23/2012','MM/DD/YYYY') supply_date, "customer_1" as a customer, "item_1" as point 0 as the cost of dual union all
Select 'vendor_1' vendor, to_date('1/6/2012','MM/DD/YYYY') supply_date, "customer_2" as a customer, "item_1" like item1, 160 as cost of double union all
Select 'vendor_1' vendor, to_date('1/7/2012','MM/DD/YYYY') supply_date, "customer_2" as a customer, "item_1" like item1, 170 as cost of double union all
Select 'vendor_1' vendor, to_date('1/8/2012','MM/DD/YYYY') supply_date, "customer_2" as a customer, "item_1" like item1, 180 as cost of double union all
Select 'vendor_1' vendor, to_date('1/9/2012','MM/DD/YYYY') supply_date, "customer_2" as a customer, "item_1" like item1, 190 as cost of double union all
Select 'vendor_1' vendor, to_date('1/20/2012','MM/DD/YYYY') supply_date, "customer_2" as a customer, "item_1" like item1, 300 as cost of double)
IT'S MY SECOND TABLE: TEMP_WEEK
WITH temp_week (s)
SELECT January 1, 2012 to 07/01/2012 ' AS the week of all the double union
SELECT August 1, 2012 to 14/01/2012 ' AS the week of all the double union
January 15, 2012 to 21/01/2012 ' AS the week of all the double union
SELECT January 22, 2012 to 28/01/2012 ' AS the week of all the double union
(SELECT 29 January 2012 to 31/01/2012 ' WEEK of double)
To find weekly sales that I wrote query below:
SELECT week, supplier, customer, SUM (cost)
(SELECT week, supplier, customer, TOTAL costs (cost)
FROM (SELECT BOX
WHEN TO_NUMBER (TO_CHAR (TRUNC (supply_date), 'DD')) BETWEEN 1 AND 7 MAY
January 1, 2012 to 07/01/2012 '
WHEN TO_NUMBER (TO_CHAR (TRUNC (supply_date), 'DD')) BETWEEN 8 AND 14 MAY
14/01/2012, 1 August 2012'
WHEN TO_NUMBER (TO_CHAR (TRUNC (supply_date), 'DD')) BETWEEN 15 AND 21 THEN
January 15, 2012 to 21/01/2012 '
WHEN TO_NUMBER (TO_CHAR (TRUNC (supply_date), 'DD')) BETWEEN 22 AND 28 and THEN
January 22, 2012 to 28/01/2012 '
WHEN TO_NUMBER (TO_CHAR (TRUNC (supply_date), 'DD')) BETWEEN 29 AND 31 MAY
29 January 2012 to 31/01/2012 '
END
week, supplier, customer, cost
REPORT)
GROUP BY week, supplier, customer
UNION ALL
SELECT tw.week, vendor, customer or 0
(SELECT week, supplier, customer, TOTAL costs (cost)
FROM (SELECT BOX
WHEN TO_NUMBER (TO_CHAR (TRUNC (supply_date), 'DD')) BETWEEN 1 AND 7 MAY
January 1, 2012 to 07/01/2012 '
WHEN TO_NUMBER (TO_CHAR (TRUNC (supply_date), 'DD')) BETWEEN 8 AND 14 MAY
14/01/2012, 1 August 2012'
WHEN TO_NUMBER (TO_CHAR (TRUNC (supply_date), 'DD')) BETWEEN 15 AND 21 THEN
January 15, 2012 to 21/01/2012 '
WHEN TO_NUMBER (TO_CHAR (TRUNC (supply_date), 'DD')) BETWEEN 22 AND 28 and THEN
January 22, 2012 to 28/01/2012 '
WHEN TO_NUMBER (TO_CHAR (TRUNC (supply_date), 'DD')) BETWEEN 29 AND 31 MAY
29 January 2012 to 31/01/2012 '
END
week, supplier, customer, cost
REPORT)
GROUP BY week, supplier, customer), temp_week tw)
GROUP BY week, supplier, customer
ORDER BY supplier, customer, week;
with above query I get below output:
with output voltage)
Select January 1, 2012 to 07/01/2012 ' week, 'vendor_1' as a provider, "customer_1" as a customer, 500 as cost of double union all
Select August 1, 2012, to 14/01/2012 ' week, 'vendor_1' as a provider, "customer_1" as a customer, 200 as cost of double union all
Select January 15, 2012 to 21/01/2012 ' week, 'vendor_1' as a provider, "customer_1" as a customer, 0 as the cost of dual union all
Select January 22, 2012 to 28/01/2012 ' week, 'vendor_1' as a provider, "customer_1" as a customer, 0 as the cost of dual union all
Select the 29 January 2012 to 31/01/2012 ' week, 'vendor_1' as a provider, "customer_1" as a customer, 0 as the cost of dual union all
Select January 1, 2012 to 07/01/2012 ' week, 'vendor_1' as a provider, "customer_2" as a customer, 330 as costs of double union all
Select August 1, 2012, to 14/01/2012 ' week, 'vendor_1' as a provider, "customer_2" as a customer, 370 as cost of double union all
Select January 15, 2012 to 21/01/2012 ' week, 'vendor_1' as a provider, "customer_2" as a customer, 300 as cost of double union all
Select January 22, 2012 to 28/01/2012 ' week, 'vendor_1' as a provider, "customer_2" as a customer, 0 as the cost of dual union all
Select the 29 January 2012 to 31/01/2012 ' week, 'vendor_1' as a provider, "customer_2" as a customer, double cost of 0)
Clearly, I used cross join. But I want to get the same result with another way. I don't want to use cross join and Union
Please help me in this.What you desire can be accomplished using the outer join partitioned.
The documentation shows an example of [url http://docs.oracle.com/cd/E11882_01/server.112/e26088/statements_10002.htm#i2177515] this way to fill the gaps in the data.Here's how you can use it in your case:
SQL> with report as ( 2 select 'vendor_1' as vendor,to_date('1/1/2012','DD/MM/YYYY') supply_date, 'customer_1'as customer,'item_1' as item1, 110 as cost from dual union all 3 select 'vendor_1' as vendor,to_date('1/3/2012','MM/DD/YYYY') supply_date,'customer_1'as customer, 'item_1' as item1,120 as c ost from dual union all 4 select 'vendor_1' as vendor,to_date('1/3/2012','MM/DD/YYYY') supply_date, 'customer_1'as customer, 'item_1' as item1,130 as cost from dual union all 5 select 'vendor_1' as vendor,to_date('1/4/2012','MM/DD/YYYY') supply_date,'customer_1'as customer, 'item_1' as item1,140 as c ost from dual union all 6 select 'vendor_1' as vendor,to_date('1/10/2012','MM/DD/YYYY') supply_date, 'customer_1'as customer, 'item_1' as item ,200as cost from dual union all 7 select 'vendor_1' as vendor,to_date('1/23/2012','MM/DD/YYYY') supply_date, 'customer_1'as customer, 'item_1' as item,0 as co st from dual union all 8 select 'vendor_1' as vendor,to_date('1/6/2012','MM/DD/YYYY') supply_date,'customer_2'as customer, 'item_1' as item1,160 as c ost from dual union all 9 select 'vendor_1' as vendor,to_date('1/7/2012','MM/DD/YYYY') supply_date,'customer_2'as customer, 'item_1' as item1,170 as c ost from dual union all 10 select 'vendor_1' as vendor,to_date('1/8/2012','MM/DD/YYYY') supply_date,'customer_2'as customer, 'item_1' as item1,180 as c ost from dual union all 11 select 'vendor_1' as vendor,to_date('1/9/2012','MM/DD/YYYY') supply_date,'customer_2'as customer,'item_1' as item1,190 as co st from dual union all 12 select 'vendor_1' as vendor,to_date('1/20/2012','MM/DD/YYYY') supply_date,'customer_2'as customer,'item_1' as item1,300 as c ost from dual 13 ), weeks as ( 14 select to_date('1/1/2012','DD/MM/YYYY') + (level-1)*7 week_start 15 , to_date('1/1/2012','DD/MM/YYYY') + (level-1)*7 + 6 week_end 16 , level week_pseudo_id 17 from dual 18 connect by level <= 5 /* substitute desired number of weeks */ 19 ) 20 -- 21 -- end-of-test-data 22 -- 23 select to_char(max(weeks.week_start),'DD/MM/YYYY') 24 || ' to ' || 25 to_char(max(weeks.week_end),'DD/MM/YYYY') week 26 , vendor 27 , customer 28 , nvl(sum(cost),0) cost 29 from report 30 partition by (vendor, customer) 31 right outer join weeks 32 on weeks.week_start <= report.supply_date 33 and weeks.week_end >= report.supply_date 34 group by 35 vendor 36 , customer 37 , week_pseudo_id 38 order by 39 vendor 40 , customer 41 , week_pseudo_id 42 / WEEK VENDOR CUSTOMER COST ------------------------ -------- ---------- ---------- 01/01/2012 to 07/01/2012 vendor_1 customer_1 500 08/01/2012 to 14/01/2012 vendor_1 customer_1 200 15/01/2012 to 21/01/2012 vendor_1 customer_1 0 22/01/2012 to 28/01/2012 vendor_1 customer_1 0 29/01/2012 to 04/02/2012 vendor_1 customer_1 0 01/01/2012 to 07/01/2012 vendor_1 customer_2 330 08/01/2012 to 14/01/2012 vendor_1 customer_2 370 15/01/2012 to 21/01/2012 vendor_1 customer_2 300 22/01/2012 to 28/01/2012 vendor_1 customer_2 0 29/01/2012 to 04/02/2012 vendor_1 customer_2 0 10 rows selected.
I have redesigned weeks of date columns for the join which will probably perform better and can possibly use indexes.
I assume that you have no time portion in your supply_date data? If you do, then week_end will need to be modified. -
Hello
I have a table with two fields that have 1-> n relationship.
Ex: TableA Field1 and Field2.
For a value of field2 there may be several Field1 in TableA (essentially field2 is part of categorization for fiel1).
In the query I want to determine which records where, for particular values of field2 only field exists.
Ex:
Field1 Field2
1A
2A
3B
4 C
D 5
D 6
For the above case the query should return only the records
Field1 Field2
3B
4 C
Please help me accomplish this query...
Thank you
RajaHello
Raja Guibert wrote:
Frank Merci for the reply,
Can you please help me understand why the min function is required on Field1...Here are the ABCS of the GROUP BY.
When you use an aggregate (such as COUNT) function in a query, then everything in the SELECT clause must be:
a ggregate function,
expressions (b), the GROUP B, or
c a Cadding
or an expression composed entirely of the foregoing.Field1 is none of them. We cannot add Field1 to the GROUP BY list, because we need all the lines for each set Field2 in the same group.
I can simply use
Select field2 from tableA having count (*) = 1 group of Field2;
Of course, you can do it if you don't need field1 in the results.
-
How do I get the data of "Regulatory BOM" Formulation with SQL query output
Hello
We would like to implement a State of BiPublisher that displays "Regulation BOM" (wording-> click on TAB Formulation on exit Popup-> TAB Composition) information table.
How could get us this information with an SQL query?
Thank you
Annarosa
Hi, given 'Regulatory BOM' output of the Formulation are more complicated than expected. Attached is an example. You can test and make the appropriate changes to your report.
-
Hello all,.
I run the query below
Select c.name_line1, c.name_line2
of tabele c where dra_code = 115
and dus_num = 111111
The output of the query shows name_line1 = name of family and Name_line2 = first name and middle name.
I need help to change the query to return only the name of the Name_line2.
Trat kindly as urgentregexp_count(name, '[[:space:]]') = length(name) - length(replace(name,' '))
with data as ( select 'Last_Name First_Name' name from dual union select 'Last_Name First_Name Middle_Name' name from dual ) select CASE when length(name) - length(replace(name,' ')) = 1 then name ELSE substr(name, 1, regexp_instr(name, '[[:space:]]', 1, 2) - 1) END name from data; NAME -------------------------------- Last_Name First_Name Last_Name First_Name 2 rows selected.
Try to use the function REGEXP_COUNT returns the invalid identifier.
select * from v$version
set linesize 200 col name for a40 col name_edit for a40 col text1 for a20 col text2 for a20 col text3 for a20 with data as ( select 'LastName FirstName' name from dual union select 'LastName FirstName MiddleName' name from dual ) select name, CASE when length(name) - length(replace(name,' ')) = 1 then name ELSE substr(name, 1, regexp_instr(name, '[[:space:]]', 1, 2) - 1) END name_edit, regexp_substr(name||' ', '[[:alpha:]]+. ', 1, 1) text1, regexp_substr(name||' ', '[[:alpha:]]+. ', 1, 2) text2, regexp_substr(name||' ', '[[:alpha:]]+. ', 1, 3) text3 from data; NAME NAME_EDIT TEXT1 TEXT2 TEXT3 ---------------------------------------- ---------------------------------------- -------------------- -------------------- -------------------- LastName FirstName LastName FirstName LastName FirstName LastName FirstName MiddleName LastName FirstName LastName FirstName MiddleName 2 rows selected.
-
Hi all
Here is the sql query,
Select papf.employee_number,
-papf.full_name, ppa.effective_date, pp.payroll_name,
PET.element_name,
PIV. Name input_value,
prrv.result_value
-, ppa.payroll_action_id, ppa.time_period_id
Of
Apps.pay_payroll_actions App,
pay_assignment_actions AAP,
pay_payrolls_f pp,
pay_run_results prr,
prrv pay_run_result_values,
pay_input_values_f piv,
animal pay_element_types_f,
Apps.per_all_assignments_f ADP,
Apps.per_all_people_f women's wear
-where ppa.payroll_action_id =: payroll_action_id - give your payroll_action_id
where ppa.payroll_id =: payroll_id
and ppa.payroll_action_id =: payroll_action_id
- and paa.assignment_action_id =: assignment_action_id
and ppa.payroll_action_id = paa.payroll_action_id
and ppa.payroll_id = pp.payroll_id
and paa.assignment_action_id = prr.assignment_action_id
and prr.run_result_id = prrv.run_result_id
and prrv.input_value_id = piv.input_value_id
and piv.element_type_id = pet.element_type_id
and paaf.assignment_id = paa.assignment_id
and paaf.person_id = papf.person_id
and trunc (sysdate) between pp.effective_start_date and pp.effective_end_date
and trunc (sysdate) between pet.effective_start_date and pet.effective_end_date
and trunc (sysdate) between piv.effective_start_date and piv.effective_end_date
and trunc (sysdate) between paaf.effective_start_date and paaf.effective_end_date
and trunc (sysdate) between papf.effective_start_date and papf.effective_end_date
- and papf.employee_number = '1'
- and ppa.effective_date = July 22, 2014"
and pet.element_name in ('Local Mission allowance', "Compensation of Mission International")
order by 1.3
The result is:
Employee_number Element_Name Input_Value Result_value
1 compensation of Mission international day amount 1000
1 compensation of international Mission Distance days 4
1 value to pay compensation of 1200 International Mission
1 International Mission allowance Start Date 01/01/2014
1 compensation of Mission international day amount 800
1 compensation of international Mission Distance days 10
1 International Mission allowance pay value 2000
1 International Mission allowance Start Date 01/02/2014
1 compensation of Mission local day amount 500
1 compensation of local Mission Distance days 10
1 Mission allowance paid local value 1000
1 compensation of local Mission Start Date 01/11/2014
Desired output:
Employee_number Element_Name Day_Amount Distance_Days Pay_Value Start_Date
1 compensation of international Mission 1000, 1200 4 2014/01/01
1
International Mission allowance 800 10 2000 01/02/2014 1 Mission local compensation 500 10 1000 01/11/2014 Please suggest.
INSERT statement:
TOGETHER TO DEFINE
Insert into APPS. PER_ALL_PEOPLE_F
(EMPLOYEE_NUMBER, NOM_ELEMENT, INPUT_VALUE, RESULT_VALUE)
Values
('1', 'International Mission allowance', 'Day amount', '1000');
Insert into APPS. PER_ALL_PEOPLE_F
(EMPLOYEE_NUMBER, NOM_ELEMENT, INPUT_VALUE, RESULT_VALUE)
Values
('1', 'International Mission allowance', 'Day amount', '1000');
Insert into APPS. PER_ALL_PEOPLE_F
(EMPLOYEE_NUMBER, NOM_ELEMENT, INPUT_VALUE, RESULT_VALUE)
Values
('1', 'International Mission allowance', 'number of orders', '196');
Insert into APPS. PER_ALL_PEOPLE_F
(EMPLOYEE_NUMBER, NOM_ELEMENT, INPUT_VALUE, RESULT_VALUE)
Values
('1', 'International Mission allowance', 'number of orders', '195');
Insert into APPS. PER_ALL_PEOPLE_F
(EMPLOYEE_NUMBER, NOM_ELEMENT, INPUT_VALUE, RESULT_VALUE)
Values
('1', 'International Mission allowance', ' Distance days, 4 ");
Insert into APPS. PER_ALL_PEOPLE_F
(EMPLOYEE_NUMBER, NOM_ELEMENT, INPUT_VALUE, RESULT_VALUE)
Values
('1', 'International Mission allowance', ' Distance days, 1 ");
Insert into APPS. PER_ALL_PEOPLE_F
(EMPLOYEE_NUMBER, NOM_ELEMENT, INPUT_VALUE, RESULT_VALUE)
Values
("1', 'International Mission allowance', 'employee Category", "scale of employment medical cities");
Insert into APPS. PER_ALL_PEOPLE_F
(EMPLOYEE_NUMBER, NOM_ELEMENT, INPUT_VALUE, RESULT_VALUE)
Values
("1', 'International Mission allowance', 'employee Category", "scale of employment medical cities");
Insert into APPS. PER_ALL_PEOPLE_F
(EMPLOYEE_NUMBER, NOM_ELEMENT, INPUT_VALUE, RESULT_VALUE)
Values
('1', 'International Mission allowance', 'Class level', 'G3');
Insert into APPS. PER_ALL_PEOPLE_F
(EMPLOYEE_NUMBER, NOM_ELEMENT, INPUT_VALUE, RESULT_VALUE)
Values
('1', 'International Mission allowance', 'Class level', 'G3');
Insert into APPS. PER_ALL_PEOPLE_F
(EMPLOYEE_NUMBER, NOM_ELEMENT, INPUT_VALUE, RESULT_VALUE)
Values
('1', 'International Mission allowance', 'class of employment, ' ');
Insert into APPS. PER_ALL_PEOPLE_F
(EMPLOYEE_NUMBER, NOM_ELEMENT, INPUT_VALUE, RESULT_VALUE)
Values
('1', 'International Mission allowance', 'class of employment, ' ');
Insert into APPS. PER_ALL_PEOPLE_F
(EMPLOYEE_NUMBER, NOM_ELEMENT, INPUT_VALUE, RESULT_VALUE)
Values
('1', 'International Mission allowance', 'Country of Mission', ' 3003 - Kuwait ");
Insert into APPS. PER_ALL_PEOPLE_F
(EMPLOYEE_NUMBER, NOM_ELEMENT, INPUT_VALUE, RESULT_VALUE)
Values
('1', 'International Mission allowance', 'Country of Mission', ' 2004 - Canada ");
Insert into APPS. PER_ALL_PEOPLE_F
(EMPLOYEE_NUMBER, NOM_ELEMENT, INPUT_VALUE, RESULT_VALUE)
Values
('1', 'International Mission allowance', ' Mission days, 4' ");
Insert into APPS. PER_ALL_PEOPLE_F
(EMPLOYEE_NUMBER, NOM_ELEMENT, INPUT_VALUE, RESULT_VALUE)
Values
('1', 'International Mission allowance', ' Mission days, 3' ");
Insert into APPS. PER_ALL_PEOPLE_F
(EMPLOYEE_NUMBER, NOM_ELEMENT, INPUT_VALUE, RESULT_VALUE)
Values
('1', 'compensation of Mission international","End of Mission Date"' 2014/07/10 00:00:00 ');
Insert into APPS. PER_ALL_PEOPLE_F
(EMPLOYEE_NUMBER, NOM_ELEMENT, INPUT_VALUE, RESULT_VALUE)
Values
('1', 'compensation of Mission international","End of Mission Date"' 2014/07/19 00:00:00 ');
Insert into APPS. PER_ALL_PEOPLE_F
(EMPLOYEE_NUMBER, NOM_ELEMENT, INPUT_VALUE, RESULT_VALUE)
Values
('1', 'compensation of Mission international", 'Mission Start Date', ' 2014/07/07 00:00:00 ');
Insert into APPS. PER_ALL_PEOPLE_F
(EMPLOYEE_NUMBER, NOM_ELEMENT, INPUT_VALUE, RESULT_VALUE)
Values
('1', 'compensation of Mission international", 'Mission Start Date', ' 2014/07/17 00:00:00 ');
Insert into APPS. PER_ALL_PEOPLE_F
(EMPLOYEE_NUMBER, NOM_ELEMENT, INPUT_VALUE, RESULT_VALUE)
Values
('1', 'International Mission allowance', 'value of pay', '3000');
Insert into APPS. PER_ALL_PEOPLE_F
(EMPLOYEE_NUMBER, NOM_ELEMENT, INPUT_VALUE, RESULT_VALUE)
Values
('1', 'International Mission allowance', 'value of pay', '4000');
00:00 ');
Insert into APPS. PER_ALL_PEOPLE_F
(EMPLOYEE_NUMBER, NOM_ELEMENT, INPUT_VALUE, RESULT_VALUE)
Values
('70', 'Local Mission allowance', 'number of orders', '45');
Insert into APPS. PER_ALL_PEOPLE_F
(EMPLOYEE_NUMBER, NOM_ELEMENT, INPUT_VALUE, RESULT_VALUE)
Values
('70', 'Local Mission allowance', 'number of orders', "456789");
Insert into APPS. PER_ALL_PEOPLE_F
(EMPLOYEE_NUMBER, NOM_ELEMENT, INPUT_VALUE, RESULT_VALUE)
Values
('70 ', 'local Mission allowance', ' away days '0' ");
Insert into APPS. PER_ALL_PEOPLE_F
(EMPLOYEE_NUMBER, NOM_ELEMENT, INPUT_VALUE, RESULT_VALUE)
Values
('70 ', 'local Mission allowance', ' Distance days, 1 ");
Insert into APPS. PER_ALL_PEOPLE_F
(EMPLOYEE_NUMBER, NOM_ELEMENT, INPUT_VALUE, RESULT_VALUE)
Values
('70 ', 'local Mission allowance', 'Provided food', 'Y');
Insert into APPS. PER_ALL_PEOPLE_F
(EMPLOYEE_NUMBER, NOM_ELEMENT, INPUT_VALUE, RESULT_VALUE)
Values
('70', 'compensation of local Mission","Accommodation provided", 'Y');
Insert into APPS. PER_ALL_PEOPLE_F
(EMPLOYEE_NUMBER, NOM_ELEMENT, INPUT_VALUE, RESULT_VALUE)
Values
('70', 'compensation of local Mission","Accommodation provided", 'Y');
Insert into APPS. PER_ALL_PEOPLE_F
(EMPLOYEE_NUMBER, NOM_ELEMENT, INPUT_VALUE, RESULT_VALUE)
Values
('70 ', "local Mission allowance", "Mission City", "AL MEDINA");
Insert into APPS. PER_ALL_PEOPLE_F
(EMPLOYEE_NUMBER, NOM_ELEMENT, INPUT_VALUE, RESULT_VALUE)
Values
('70 ', "local Mission allowance", "Mission City", "RIYADH");
Insert into APPS. PER_ALL_PEOPLE_F
(EMPLOYEE_NUMBER, NOM_ELEMENT, INPUT_VALUE, RESULT_VALUE)
Values
('70 ', 'local Mission allowance', ' Mission days, 4' ");
Insert into APPS. PER_ALL_PEOPLE_F
(EMPLOYEE_NUMBER, NOM_ELEMENT, INPUT_VALUE, RESULT_VALUE)
Values
('70 ', 'local Mission allowance', ' Mission days, 5' ");
Insert into APPS. PER_ALL_PEOPLE_F
(EMPLOYEE_NUMBER, NOM_ELEMENT, INPUT_VALUE, RESULT_VALUE)
Values
('70', 'Local Mission allowance', 'End of Mission Date' ' 2014/06/16 00:00:00 ');
Insert into APPS. PER_ALL_PEOPLE_F
(EMPLOYEE_NUMBER, NOM_ELEMENT, INPUT_VALUE, RESULT_VALUE)
Values
('70', 'Local Mission allowance', 'End of Mission Date' ' 2014-06-14 00:00:00 ');
Insert into APPS. PER_ALL_PEOPLE_F
(EMPLOYEE_NUMBER, NOM_ELEMENT, INPUT_VALUE, RESULT_VALUE)
Values
('70', 'Local Mission allowance', 'Mission Start Date', ' 2014/06/13 00:00:00 ');
Insert into APPS. PER_ALL_PEOPLE_F
(EMPLOYEE_NUMBER, NOM_ELEMENT, INPUT_VALUE, RESULT_VALUE)
Values
('70', 'Local Mission allowance', 'Mission Start Date', ' 2014/06/10 00:00:00 ');
Thank you very much in advance.
Kind regards
Afzal.
So then... something like this:
SELECT employee_number
element_name
MAX (decode (input_value, 'Day amount', result_value)) AS day_amount
MAX (decode (input_value, 'Days of Distance', result_value)) AS Distance_Days
, MAX (decode (input_value, 'Value of pay', result_value)) AS Pay_Value
MAX (decode (input_value, 'Start Date', result_value)) AS Start_Date
from (SELECT papf.employee_number
pet.element_name
piv.NAME input_value
prrv.result_value
prrv.run_result_id
OF apps.pay_payroll_actions App
pay_assignment_actions PAA
pay_payrolls_f pp
pay_run_results prr
pay_run_result_values prrv
pay_input_values_f piv
pay_element_types_f pet
apps.per_all_assignments_f ADP
apps.per_all_people_f women's wear
-where ppa.payroll_action_id =: payroll_action_id - give your payroll_action_id
WHERE ppa.payroll_id =: payroll_id
AND ppa.payroll_action_id =: payroll_action_id
- and paa.assignment_action_id =: assignment_action_id
AND ppa.payroll_action_id = paa.payroll_action_id
AND ppa.payroll_id = pp.payroll_id
AND paa.assignment_action_id = prr.assignment_action_id
AND prr.run_result_id = prrv.run_result_id
AND prrv.input_value_id = piv.input_value_id
AND piv.element_type_id = pet.element_type_id
AND paaf.assignment_id = paa.assignment_id
AND paaf.person_id = papf.person_id
AND trunc (sysdate) BETWEEN pp.effective_start_date AND pp.effective_end_date
AND trunc (sysdate) BETWEEN pet.effective_start_date AND pet.effective_end_date
AND trunc (sysdate) BETWEEN piv.effective_start_date AND piv.effective_end_date
AND trunc (sysdate) BETWEEN paaf.effective_start_date AND paaf.effective_end_date
AND trunc (sysdate) BETWEEN papf.effective_start_date AND papf.effective_end_date
AND pet.element_name IN ('local Mission allowance', 'International Mission'))
GROUP BY employee_number
element_name
run_result_id
;
You should get your desired result.
Roger
-
Dear all,
I have a sql like query below
SELECT min (G.TRANSACTION_DATE), D.REQUEST_NUMBER
MTL_TXN_REQUEST_HEADERS D,.
MTL_TXN_REQUEST_LINES, E.
MTL_MATERIAL_TRANSACTIONS G,.
Mtl_Transaction_Types I have
WHERE D.HEADER_ID = E.HEADER_ID
AND G.TRANSACTION_TYPE_ID = I.TRANSACTION_TYPE_ID
AND Upper (I.Transaction_Type_Name) = Upper ('TEC outcome')
AND E.LINE_ID = G.MOVE_ORDER_LINE_ID
AND D.MOVE_ORDER_TYPE = 5
TO_DATE (G.TRANSACTION_DATE) BETWEEN TO_DATE('01-JAN-2014') AND TO_DATE('31-DEC-2014')
D.REQUEST_NUMBER GROUP
I need to get the first number of the application and finally ask for number based on the date of the transaction, how can I get the number of name application and based on the date of the transaction for the same query, please help me.
above query is back under results
If the query should return a line with the number of application like 2383 based on minimum transaction date and another column based on the maximum transaction date, please help me.
so in the example above, it must return
FIRST REQUEST NUMBER LAST NUMBER
2383 1886
Thank you
select min(request_number) keep(dense_rank first order by transaction_date asc ) request_number_min , min(request_number) keep(dense_rank first order by transaction_date desc) request_number_max from ( select min(g.transaction_date) transaction_date , d.request_number from mtl_txn_request_headers d , mtl_txn_request_lines e , mtl_material_transactions g , mtl_transaction_types i where d.header_id = e.header_id and g.transaction_type_id = i.transaction_type_id and upper(i.transaction_type_name) = upper('WIP Issue') and e.line_id = g.move_order_line_id and d.move_order_type = 5 and to_date(g.transaction_date) between to_date('01-jan-2014') and to_date('31-dec-2014') group by d.request_number )
-
Need help with sql query performance
Dear all,
I have a sql like query below, I need to give the following query please help me identify which statement I should tune to have better performanece.
Select rownum LINE_NUM,
A.LINE_ID,
TO_CHAR (A.INVITMID),
TO_NUMBER (A.PICKQTY),
UNLOADINGPNT NULL,
RRNUM NULL,
WORKORDNUM NULL,
WORKORDDESC NULL,
A.PONUM,
DTR_DUMB NULL,
A.DESCRIPTION,
FROM_SUB NULL,
TO_SUB NULL,
NO SOURCE,
ASSET_NUMBER NULL,
A.RECEIPTNUM,
MOVEORD NULL,
FROM_LOC NULL,
TO_LOC NULL,
MSD_NUM NULL,
CONTAIN_LINE NULL,
A.UOM,
A.PO_RELEASE
de)
Select headerid Po.Po_Header_Id,
rcv1. Po_Line_Id LINE_ID,
rcv1.item_id INVITMID,
(NVL(Rcv1.Transact_Qty,0)-NVL(rcv2.transact_qty,0)) PICKQTY,
Po.Segment1 PONUM,
Rcv1.Receipt_Num RECEIPTNUM,
Rcv1.Item_Desc DESCRIPTION,
Rcv1.Transact_Uom GLU,
Rcv1.Po_release
Po_Headers_All in.,.
(Select rcv3. Po_Header_Id, RCV3.receipt_num, rcv3. Po_Line_Id, rcv3. Destination_Type_Code, rcv3. Item_Id, rcv3. Item_Desc, rcv3. Transact_Uom, SUM (rcv3. Transact_Qty) Transact_Qty, rcv3. PO_RELEASE OF)
SELECT A.Po_Header_Id,
C.RECEIPT_NUM receipt_num,
A.Po_Line_Id,
A.Destination_Type_Code,
B.Item_Id,
B.item_description Item_Desc,
A.UNIT_OF_MEASURE Transact_Uom,
A.QUANTITY Transact_Qty,
D.RELEASE_NUM PO_RELEASE
OF RCV_TRANSACTIONS,.
RCV_SHIPMENT_HEADERS C.
B RCV_SHIPMENT_LINES,
PO_RELEASES_ALL D
WHERE C.SHIPMENT_HEADER_ID = A.SHIPMENT_HEADER_ID
AND B.SHIPMENT_LINE_ID = A.SHIPMENT_LINE_ID
AND UPPER (A.Transaction_Type) = "to DELIVER".
AND higher (A.Destination_Type_Code) = "EXPENSES".
AND D.PO_RELEASE_ID = A.PO_RELEASE_ID
UNION ALL
SELECT A.Po_Header_Id,
C.RECEIPT_NUM receipt_num,
A.Po_Line_Id,
A.Destination_Type_Code,
B.Item_Id,
B.item_description Item_Desc,
A.UNIT_OF_MEASURE Transact_Uom,
A.QUANTITY Transact_Qty,
D.RELEASE_NUM PO_RELEASE
OF RCV_TRANSACTIONS,.
RCV_SHIPMENT_HEADERS C.
B RCV_SHIPMENT_LINES,
PO_RELEASES_ALL D
WHERE C.SHIPMENT_HEADER_ID = A.SHIPMENT_HEADER_ID
AND B.SHIPMENT_LINE_ID = A.SHIPMENT_LINE_ID
AND B.ITEM_ID IS NULL
AND UPPER (A.Transaction_Type) = "to DELIVER".
AND higher (A.Destination_Type_Code) = "WORKSHOP".
D.PO_RELEASE_ID AND = A.PO_RELEASE_ID) rcv3
GROUP BY rcv3. Po_Header_Id, RCV3.receipt_num, rcv3. Po_Line_Id, rcv3. Destination_Type_Code, rcv3. Item_Id, rcv3. Item_Desc, rcv3. Transact_Uom, rcv3. Rcv1 PO_RELEASE),
(SELECT A.PO_LINE_ID,
Sum (A.Quantity) transact_qty,
A.PO_HEADER_ID,
C.RECEIPT_NUM
OF RCV_TRANSACTIONS,.
RCV_SHIPMENT_HEADERS C.
B RCV_SHIPMENT_LINES,
PO_RELEASES_ALL D
WHERE C.SHIPMENT_HEADER_ID = A.SHIPMENT_HEADER_ID
AND B.SHIPMENT_LINE_ID = A.SHIPMENT_LINE_ID
AND UPPER (A.Transaction_Type) = "RETURN to the RECEPTION"
AND D.PO_RELEASE_ID = A.PO_RELEASE_ID
A.PO_LINE_ID, A.PO_HEADER_ID, C.RECEIPT_NUM GROUP) Rcv2
Where Po.Po_Header_Id = Rcv1.Po_Header_Id (+)
And Rcv1.Po_Line_Id = Rcv2.Po_Line_Id (+)
And Rcv1.Receipt_Num = Rcv2.Receipt_Num (+)
And Rcv1.Transact_Qty <>Nvl(Rcv2.Transact_Qty,999999999)
Group of po.po_header_id, rcv1.po_line_id, po.segment1, rcv1.receipt_num, rcv1.item_id, Rcv1.Item_Desc, rcv1. TRANSACT_UOM, rcv1. PO_RELEASE, (NVL(Rcv1.Transact_Qty,0)-NVL(RCV2.transact_qty,0))) has
Is my version of the database: Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 - 64 bit Production
Please find the attached PLAN to EXPLAIN.
Thank you
May be essentially the same join (between a, b, c and d) twice instead of three times
sounds like it could be done with a single join (between a, b, c, and d), but you do not some columns than the columns of rcv1 rcv2
We can work on what we can see only
Select rownum line_num,
rcv1.po_line_id line_id,
TO_CHAR (rcv1.item_id) invitmid,
NVL(rcv1.transact_qty,0) - nvl(rcv2.transact_qty,0) pickqty,
unloadingpnt null,
rrnum null,
workordnum null,
workorddesc null,
Po. Ponum Segment1,
dtr_dumb null,
description of the rcv1.item_desc,
from_sub null,
to_sub null,
No source,
asset_number null,
rcv1.receipt_num receiptnum,
moveord null,
from_loc null,
to_loc null,
msd_num null,
contain_line null,
Glu rcv1.transact_uom,
rcv1.po_release
of po_headers_all in.
left outer join
(select a.po_header_id,
c.receipt_num,
a.po_line_id,
a.destination_type_code,
b.item_id,
b.item_description item_desc,
a.unit_of_measure transact_uom,
Sum (a.Quantity) transact_qty,
d.release_num po_release
from (select shipment_header_id,
shipment_line_id,
po_release_id,
po_header_id,
po_line_id,
destination_type_code,
unit_of_measure,
quantity
of rcv_transactions
where upper (a.transaction_type) = "to DELIVER".
and upper (a.destination_type_code) ('charge', 'WORKSHOP')
) a
inner join
rcv_shipment_lines b
On a.shipment_line_id = b.shipment_line_id
inner join
c rcv_shipment_headers
On a.shipment_header_id = c.shipment_header_id
left outer join
po_releases_all d
On a.po_release_id = d.po_release_id
where upper (a.destination_type_code) = "EXPENSES".
or (upper (a.destination_type_code) = 'WORKSHOP'
and b.item_id is null
)
A.po_header_id group,
c.receipt_num,
a.po_line_id,
a.destination_type_code,
b.item_id,
b.item_description,
a.unit_of_measure,
d.release_num
) rcv1
On po.po_header_id = rcv1.po_header_id
left outer join
(select a.po_line_id,
Sum (a.Quantity) transact_qty,
a.po_header_id,
c.receipt_num
from (select shipment_header_id,
shipment_line_id,
po_release_id,
po_header_id,
quantity
of rcv_transactions
where upper (a.transaction_type) = "RETURN to THE RECIPIENTS.
) a
inner join
rcv_shipment_lines b
On a.shipment_line_id = b.shipment_line_id
inner join
c rcv_shipment_headers
On a.shipment_header_id = c.shipment_header_id
left outer join
po_releases_all d
On a.po_release_id = d.po_release_id
A.po_line_id group,
a.po_header_id,
c.receipt_num
) rcv2
On rcv1.po_line_id = rcv2.po_line_id
and rcv1.receipt_num = rcv2.receipt_num
where rcv1.transact_qty! = nvl(rcv2.transact_qty,999999999)
Concerning
Etbin
Maybe you are looking for
-
How can I convert a Document attachment in a link I can Tweet
I would also like to post a link to the document in a forum like this - accessible on the internet (but not this one) The Document, to which I am referring opens on my computer in the Microsoft Word program. I hope I expressed myself clearly - I go b
-
How to change HDD on Satellite Pro 430CDT
Can someone tell me where I could find simple instructions telling me how to take apart my old 430CDT to mount a hard drive more? I think replace drive 1.25 GB - with a 4 or 6 GB hard drive assuming the disks that I may need to adapt. I guess that th
-
HP envy h8-1534: restore
How can I get a recovery disk to restore my system to default settings?
-
ProBook 6545b: where can I find a replacement battery?
I need to buy another battery of the BIOS, but can't find it on the HP website. Any ideas? Thank you. Jeff W
-
I was able to open it in the past with XP and some computers with Windows 7.