-1
나는 다음과 같은 테이블 할당 구조가 장고 ORM : 합계 같은 열이 다른 컬럼에 따라 -
| 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;
무엇을 토륨한다 e 장고 쿼리가이 결과에 해당합니까?
, 아래의 쿼리를
을 사용할 수 있습니다 나는 매우 비슷한 작성하려했지만 쿼리가 항상 나에게 output_field에 의해 제기 FieldError을 던졌다. 감사! – minzey