テーブルの下に、これらの請求書のすべてのアイテムが であると予想しています。MySQLは2つのフィールドの合計をグループステートメントで比較します
表:
mysql> select * from allotment;
+----+------------+---------+-----------+------------+------------+
| id | invoice_id | item_id | total_qty | packed_qty | created |
+----+------------+---------+-----------+------------+------------+
| 1 | 4 | 26 | 4 | 4 | 2016-08-31 |
| 2 | 4 | 38 | 1 | 1 | 2016-08-31 |
| 3 | 5 | 39 | 16 | 8 | 2016-08-31 |
| 4 | 5 | 2 | 2 | 5 | 2016-08-31 |
+----+------------+---------+-----------+------------+------------+
マイクエリ:
mysql> SELECT invoice_id, created FROM allotment
where sum(allotment.total_qty)=sum(allotment.packed_qty)
GROUP BY invoice_id;
[**ERROR 1111 (HY000): Invalid use of group function]
私は多くの方法を適用しているが、それはうまくいきませんでした。実際には、 "sum of total_qty"
と"sum of packed_qty"
を同じ "invoice_id"
に対して比較する必要があります。
マイ期待される結果:
+------------+------------+
| invoice_id | created |
+------------+------------+
| 4 | 2016-08-31 |
Logic: Invoice_id 4, total_item = 4+1 and total_packed= 4+1
[select where total_item==total_packed]
「割当」テーブルから、この結果を取得する方法はありますか?