Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
Chilly
Starting Member
3 Posts |
Posted - 2007-03-30 : 09:41:51
|
| I am trying to extract data from an oracle database. I would like to retrieve multiple fields and group by part number with the total quantity. The script I used that will extract the data I want is as follows:SELECT ITEM.PART,CAT1.NSN,ITEM.RECEIPT_UM,ITEM.QTY,WHSE.STOCK_LEVELFROM ITEM,CAT1,WHSEWHERE ITEM.PART = CAT1.PART AND WHSE.PART = ITEM.PARTIt will display the fields I want but includes multiple lines with the same part number because the parts are serialized and have their own instance in the tableExamplePART NSN RECEIPT_UM QTY STOCK_LEVEL123 jjjjj EA 1 3123 jjjjj EA 1 3123 jjjjj EA 1 3456 kkkkk KT 2 5456 kkkkk KT 3 5How I would like the data to look like is:PART NSN RECEIPT_UM QTY STOCK_LEVEL 123 jjjjj EA 3 3456 kkkkk KT 5 5I have tried to use the SUM and group by which works if I only use part and qty from the same tableSELECT PART,SUM(QTY)FROM ITEMWHERE SC = 'CUSTOMER'GROUP BY PART;I also plan to use a where clause.Any advice or help is greatly appreciated. |
|
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2007-03-30 : 09:58:18
|
| SELECT ITEM.PART, CAT1.NSN, ITEM.RECEIPT_UM, SUM(ITEM.QTY), MAX(WHSE.STOCK_LEVEL)FROM ITEMINNER JOIN CAT1 ON CAT1.PART = ITEM.PARTINNER JOIN WHSE ON WHSE.PART = ITEM.PARTGROUP BY ITEM.PART, CAT1.NSN, ITEM.RECEIPT_UMORDER BY ITEM.PART, CAT1.NSN, ITEM.RECEIPT_UMPeter LarssonHelsingborg, Sweden |
 |
|
|
X002548
Not Just a Number
15586 Posts |
|
|
snSQL
Master Smack Fu Yak Hacker
1837 Posts |
Posted - 2007-03-30 : 10:01:14
|
This should give you what you want. I have changed the join syntax from what you had although that would also have worked, but this is the recommended syntax. Note that this is a SQL Server forum and you should rather try forums.oracle.com or dbforums.com for Oracle specific help.SELECT ITEM.PART, CAT1.NSN, ITEM.RECEIPT_UM, SUM(ITEM.QTY) AS QTY, WHSE.STOCK_LEVELFROM ITEMINNER JOIN CAT1 ON ITEM.PART = CAT1.PARTINNER JOIN WHSE ON WHSE.PART = ITEM.PARTWHERE <any non-join criteria here>GROUP BY ITEM.PART, CAT1.NSN, ITEM.RECEIPT_UM, WHSE.STOCK_LEVEL |
 |
|
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2007-03-30 : 15:00:30
|
quote: Originally posted by X002548 SELECT DISTINCT should stilll work in H'Oracle
PART NSN RECEIPT_UM QTY STOCK_LEVEL123 jjjjj EA 1 3123 jjjjj EA 1 3123 jjjjj EA 1 3456 kkkkk KT 2 5456 kkkkk KT 3 5How I would like the data to look like is:PART NSN RECEIPT_UM QTY STOCK_LEVEL 123 jjjjj EA 3 3456 kkkkk KT 5 51+1+1 = 32+3 = 5 Peter LarssonHelsingborg, Sweden |
 |
|
|
|
|
|
|
|