Help! Trying to Sum Quantity with Duplicate Rows
I have a database that have the following columns barcode, quantity, etc. The barcode colum has barcode duplicates and the corresponding quantity differs. I have been working hours trying to solve how to sum each different barcode and replace the table with 1 barcode each with corresponding total quantity. So, instead of:
| 97138644756 | 3 |
| 97138644756 | 2 |
| 97138644756 | 1 |
| 97138660565 | 5 |
| 97138660565 | 4 |
| 97138661777 | 1 |
| 97138662224 | 1 |
| 97138670403 | 1 |
| 97138679239 | 1 |
| 97138714978 | 1 |
| 97138716262 | 1 |
| 97138739667 | 6 |
| 97138739667 | 7 |
| 97138739667 | 8 |
I would like it to read:
| 97138644756 | 6 |
| 97138660565 | 9 |
| 97138661777 | 1 |
| 97138662224 | 1 |
| 97138670403 | 1 |
| 97138679239 | 1 |
| 97138714978 | 1 |
| 97138716262 | 1 |
| 97138739667 | 21 |
I was using the following code, which only picks out the duplicates.
<cfquery name="CountBarcodesCart1" datasource='inventory'>
SELECT *
FROM cart1
WHERE barcode IN (
SELECT barcode
FROM cart1
GROUP BY barcode
HAVING (COUNT(barcode ) > 1))
</cfquery>
Thanks for anyone that can help with my business.
