E
E
Eugene2019-12-11 14:20:00
Yii
Eugene, 2019-12-11 14:20:00

How to calculate the quantity of each order, taking into account their quantity?

For example, there is such a table

id | code | qty
1  | 2324 | 2
2  | 2324 | 1
3  | 2324 | 5
4  | 2388 | 1
5  | 6311 | 12

You need to count the quantity of each item in the order. That is, here the product identifier is not an ID, but a code. But taking into account the fact that the goods have more of it. Well, sort in descending order, but this is the easiest here

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Valeron Sergeev, 2019-12-11
@evgen9586

SELECT DISTINCT code, SUM(qty) as count FROM orders GROUP BY code ORDER BY count DESC

code | count
6311 | 12
2324 | 8
2388 | one

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question