如何将列中包含特定item_id的列与相应的status = pending相加

时间:2013-06-12 02:20:55

标签: php html mysql mysqli phpmyadmin

这是我的表格如下:

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      |

如何从amount item_id status的特定pending获得总和{{1}}?

1 个答案:

答案 0 :(得分:4)

以下是对此的查询:

select sum(Amount)
  from TableName
 where Status = 'pending'  
   and Item_ID = 7