|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
You don't need a fax machine to get faxes. Get a fax-to-email fax number from CallWave. Try it free.
|
|
#1
|
|||
|
|||
|
Adding rows from a sql result
I need the sql to add rows of the same id from the below sql in order to get the total ammount ordered. Only some rows have the same ordnumb, but different partnumb. The composite key of ordnumb and partnumb give each ordline a unique indentifier.
select sum(ol.numbord)*count(ordnumb) from ordline ol, orders o, parts p where distinct ol.ordnumb = distinct o.ordnumb and ol.partnumb = p.partnumb order by ol.ordnumb; Need to get the total ammount ordered, for each unique order, for example Order nos = 12498, which is 2 ORDNUMB PART NUMBORD ---------- ---- ---------- 12489 AX12 11 12491 BT04 1 12491 BZ66 1 12494 CB03 4 12495 CX11 2 12498 AZ52 2 12498 BA74 4 12500 BT04 1 12504 CZ81 2 This is the wrong result SUM(OL.NUMBORD)*COUNT(DISTINCTO.ORDNUMB) ---------------------------------------- 196 Just need a little help for this newbie Please assist, and thanks is advance Cathal |
|
#2
|
|||
|
|||
|
Code:
select ol.ordnumb, ol.partnumb sum(ol.numbord) from ordline ol, parts p where ol.partnumb = p.partnumb group by ol.ordnumb, ol.partnumb order by ol.ordnumb |
![]() |
| Viewing: Dev Shed Forums > Databases > Database Management > Adding rows from a sql result |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|
|