【发布时间】:2016-07-04 13:09:22
【问题描述】:
我有如下表赋值结构:
| employee | product | process | qty |
| Swati | PROD1 | issue | 60 |
| Rohit | PROD1 | issue | 30 |
| Rohit | PROD2 | issue | 40 |
| Swati | PROD1 | receive | 40 |
| Swati | PROD2 | issue | 70 |
我希望每位员工的决赛桌看起来像这样(比如employee = 'Swati'):
| product | sum_issued | sum_received
| PROD1 | 60 | 40 |
| PROD2 | 70 | 0 |
执行此操作的 SQL 查询是:
select product
, sum(case when process='issue' then qty else 0 end) as sum_issued
, sum(case when process='receive' then qty else 0 end) as sum_received
from assignment
where employee = 'Swati'
group
by product;
对应于这个结果的 Django 查询应该是什么?
【问题讨论】: