[英]How do I sum columns that contains certain item_id in the column with corresponding status = pending
這是我的表,看起來像:
id | Prs Id | Amount | Status | Item Id| ---------------------------------------- 1 | 10 | 200 |pending | 5 | 2 | 10 | 300 |pending | 7 | 3 | 10 | 400 |pending | 9 | 4 | 10 | 100 |received| 6 | 5 | 10 | 200 |received| 8 | 6 | 10 | 300 |received| 3 | 7 | 10 | 200 |pending | 5 | 8 | 10 | 300 |pending | 7 | 9 | 10 | 400 |pending | 9 | 10 | 10 | 100 |received| 6 | 11 | 10 | 200 |received| 8 | 12 | 10 | 300 |received| 3 |
如何從也具有pending
status
的特定item_id
獲取總amount
?
這是該查詢:
select sum(Amount)
from TableName
where Status = 'pending'
and Item_ID = 7
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.