Solved

oracle query

Posted on 2013-06-06
10
171 Views
Last Modified: 2013-06-12
0
Comment
Question by:anumoses
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 49

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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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
 
LVL 49

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 49

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 49

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

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Why doesn't the Oracle optimizer use my index? Querying too much data Most Oracle developers know that an index is useful when you can use it to restrict your result set to a small number of the total rows in a table. So, the obvious side…
Checking the Alert Log in AWS RDS Oracle can be a pain through their user interface.  I made a script to download the Alert Log, look for errors, and email me the trace files.  In this article I'll describe what I did and share my script.
This video shows, step by step, how to configure Oracle Heterogeneous Services via the Generic Gateway Agent in order to make a connection from an Oracle session and access a remote SQL Server database table.
This video shows how to recover a database from a user managed backup
Suggested Courses

628 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