I have a table (Order_line_t) with the following format:
Order_ID Product_ID Quantity
-------- ---------- --------
1001 1 2
1001 2 2
1001 4 1
1002 3 5
1003 3 1
1004 6 2
1004 8 2
1005 4 4
1006 1 1
1006 5 2
1006 7 2
1007 1 3
1007 2 2
1008 3 2
1008 8 3
1009 4 2
1009 7 3
1010 8 10
My goal is to show the total quantity that has been ordered by descending popularity for each product like this: (I used my current query and clicked on Descending Filter for Column Total_Quantity to achieve this result)
Product_ID Total_Quantity
---------- --------------
8 15
4 8
3 8
7 5
1 5
2 4
6 2
5 2
I have been trying to figure this out for 3 hours, and I don’t know where I my error is. My current SQL Query is this:
SELECT Product_ID, SUM(Quantity) AS Total_Quantity
FROM Order_line_t
GROUP BY Product_ID
My Query result is this:
Product_ID Total_Quantity
---------- --------------
1 5
2 4
3 8
4 8
5 2
6 2
7 5
8 15
Thanks in advance, I am just beginning to learn SQL. Please bear with me.
OR