Need_to_select_single_query_and_groupBy_together
hi all
i have a problem in the following query. i need to fetch the rows such that i want to fetch all the records keeping "segment1" column as distinct and sum all of the corresponding "quantities" column.
select prha.segment1 --as requisition_no
,prha.creation_date
,sum(prla.quantity)
,prha.description
,(unit_price * quantity) as cost
,prla.currency_code
from PO_REQUISITION_HEADERS_ALL prha
,PO_REQUISITION_LINES_ALL prla
where to_date(prha.CREATION_DATE) between '01-Jan-2011' and '31-Jan-2011'
and prha.requisition_header_id = prla.requisition_header_id
group by prha.segment1
please help in rectifying the problem
regards,
hii
then you can try using UNION...
SELECT SEGMENT1,CREATION_DATE,DESCRIPTION,SUM1,COST,CURRENCY_CODE
FROM
SELECT PRHA.SEGMENT1
,PRHA.CREATION_DATE
,(SELECT SUM(PRLA1.QUANTITY) FROM PO_REQUISITION_LINES_ALL PRLA1 WHERE PRLA1.REQUISITION_HEADER_ID = PRHA.REQUISITION_HEADER_ID) SUM1
,PRHA.DESCRIPTION
,(UNIT_PRICE * QUANTITY) AS COST
,PRLA.CURRENCY_CODE
FROM PO_REQUISITION_HEADERS_ALL PRHA
,PO_REQUISITION_LINES_ALL PRLA
WHERE TO_DATE(PRHA.CREATION_DATE) BETWEEN '01-Jan-2011' AND '31-Jan-2011'
AND PRHA.REQUISITION_HEADER_ID = PRLA.REQUISITION_HEADER_ID
UNION
SELECT PRHA.SEGMENT1
,PRHA.CREATION_DATE
,(SELECT SUM(PRLA1.QUANTITY) FROM PO_REQUISITION_LINES_ALL PRLA1 WHERE PRLA1.REQUISITION_HEADER_ID = PRHA.REQUISITION_HEADER_ID) SUM1
,PRHA.DESCRIPTION
,(UNIT_PRICE * QUANTITY) AS COST
,PRLA.CURRENCY_CODE
FROM PO_REQUISITION_HEADERS_ALL PRHA
,PO_REQUISITION_LINES_ALL PRLA
WHERE TO_DATE(PRHA.CREATION_DATE) BETWEEN '01-Jan-2011' AND '31-Jan-2011'
AND PRHA.REQUISITION_HEADER_ID = PRLA.REQUISITION_HEADER_ID
ORDER BY SEGMENT1it is not good but i using it in UNION. because DISTINCT is not working in your query.
PS
Similar Messages
Maybe you are looking for
-
How can I delete old addresses from the automatic fill?
I set up a new account on a G4 PowerMac with 10.3.9 installed. This computer was being used previously by one of my other users. My question is: whenever the new user wants to send a new message and she types in the address she needs to use, it is se
-
I can't seem to open iTunes on my laptop. Operating W7
I've also tried going to control panel and 'Repairing'' iTunes and Q'Time
-
Mouse will not scroll with FireFox but works with Explorer
The only time my BlueTooth mouse has problems scrolling is with FireFox.
-
Extra White Space from Hidden Menu Bar
This seems to be a problem introduced by LV 2013. I have a VI that runs with the menu bar hidden. When I hit ctrl-m to see how it looks in run mode, it looks fine. When I run the VI, instead of fully hiding the menu bar, it leaves white space. This o
-
I get an error on my iPhone saying that iCloud photo library storage has run out of space and it will stop uploading photos from my phone. However, my iCloud has 1.5gb of free storage and my photo library only has about 22 photos. So, what's happenin