Solved

oracle query

Posted on 2013-06-06
10
165 Views
Last Modified: 2013-06-12
0
Comment
Question by:anumoses
  • 6
  • 4
10 Comments
 
LVL 6

Author Comment

by:anumoses
ID: 39225538
I had to give the right table creation scripts.
query-to-be-sent.sql
0
 
LVL 48

Accepted Solution

by:
PortletPaul earned 500 total points
ID: 39225929
could you please try this? it's from an earlier question please see http://sqlfiddle.com/#!4/12a49/35
I haven't yet had a chance to load all your test data and may not be able to right now (its v.late for me) - but it may help others
SELECT
        CASE 
		WHEN id = prev_id
			THEN NULL
		ELSE (
				SELECT 'EDWARD HINES' from dual
				--FROM consignee_id c
				--WHERE c.consignee_id = id
				)
		END NAME
	, wkday
    , qty
	, CASE 
		WHEN id = prev_id
			AND wkday = prev_wkday
			AND prd_typ = prev_prdtyp
			THEN NULL
		ELSE prd_typ
		END prd_typ
	, CASE 
		WHEN id = prev_id
			AND wkday = prev_wkday
			AND prd_typ = prev_prdtyp
			THEN NULL
		ELSE attrib_grp
		END attrib_grp
	, CASE 
		WHEN id = prev_id
			AND wkday = prev_wkday
			AND prd_typ = prev_prdtyp
			THEN NULL
		ELSE attrib_cod
		END attrib_cod
FROM (
      SELECT
            b.consignee_id id
          , b.week_day wkday
          , b.product_type prd_typ
          , a.attrib_group attrib_grp
          , a.attrib_code attrib_cod
          , b.qty
          , LAG(b.consignee_id) OVER (ORDER BY b.consignee_id, b.week_day) prev_id
          , LAG(b.week_day)     OVER (ORDER BY b.consignee_id, b.week_day) prev_wkday
          , LAG(b.product_type) OVER (ORDER BY b.consignee_id, b.week_day, b.product_type) prev_prdtyp
      FROM tab1 a
      RIGHT JOIN tab2 b ON a.consignee_id = b.consignee_id
          --AND a.item_no = b.item_no
          AND a.week_day = b.week_day
	)
ORDER BY
  prev_id desc
, id
, wkday
, prd_typ desc
;

Open in new window

0
 
LVL 6

Author Comment

by:anumoses
ID: 39225975
No not correct data. Please run for

Edward Hines,Jr VA Hospital

see attached. This is what I want.
correct-data.xls
0
 
LVL 6

Author Comment

by:anumoses
ID: 39226001
The earlier query I posted works fine when  attrib group and attrib code is there. Some lines do not have the group and code, but we have to show the line with week day qty and product type. That is what we are not getting to.
0
 
LVL 6

Author Comment

by:anumoses
ID: 39226139
sdstuber gave me the query that is working fine when we have attrib code and atrib group but does not pull the data when we do not have the group and code. Can someone help me please?
0
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 
LVL 48

Expert Comment

by:PortletPaul
ID: 39226201
>>No not correct data. Please run for
anumoses, if you look at my proposal you will see it has a small piece commented out

the assumption is you would uncomment that - it's not a great deal to do see lines 6,7,8

remove "from dual" and remove the 2 "--" comments

>>I haven't yet had a chance to load all your test data
as previously stated
0
 
LVL 6

Author Comment

by:anumoses
ID: 39226248
I am getting the correct data for EDW-CS0003'  Edward Hines,Jr VA Hospital
but not others.
0
 
LVL 48

Expert Comment

by:PortletPaul
ID: 39228265
anumoses, and I still have not been able to load all your data and have made no advance - hopefully others will be able to help - sorry.
0
 
LVL 6

Author Closing Comment

by:anumoses
ID: 39241937
thanks
0
 
LVL 48

Expert Comment

by:PortletPaul
ID: 39242889
thanks anumoses - I thought there was more needed still but had been unable to progress it myself - hope you have what you needed.
0

Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
how to tune this sql query 61 103
Cannot open form error 6 49
return result by latest date - oracle query 21 51
report returning null 21 52
Configuring and using Oracle Database Gateway for ODBC Introduction First, a brief summary of what a Database Gateway is.  A Gateway is a set of driver agents and configurations that allow an Oracle database to communicate with other platforms…
This post first appeared at Oracleinaction  (http://oracleinaction.com/undo-and-redo-in-oracle/)by Anju Garg (Myself). I  will demonstrate that undo for DML’s is stored both in undo tablespace and online redo logs. Then, we will analyze the reaso…
This video shows information on the Oracle Data Dictionary, starting with the Oracle documentation, explaining the different types of Data Dictionary views available by group and permissions as well as giving examples on how to retrieve data from th…
Via a live example, show how to restore a database from backup after a simulated disk failure using RMAN.

747 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now