用不同的id分隔数据-mysql或phpexcel

k4aesqcs  于 2021-06-20  发布在  Mysql
关注(0)|答案(1)|浏览(424)

我正在尝试在收据中分离不同的产品类别,以便使用mysql对主要类别和次要类别进行不同的查询。
少校的物资品种代码为771013,少校的物资品种代码为771012。也就是说,我还想得到每一张支票中订购的商品。

这是我想要的结果。


我正在使用mysql和phpexcel了解如何做到这一点。你能给我一些提示吗?用phpexcel的vlookup公式,这可能吗?

r1zhe5dt

r1zhe5dt1#

去拿收据上的东西

SELECT receipts_body.receipt_id,items.id,items.title FROM receipts_body
LEFT JOIN items ON items.id = receipts_body.item_id
ORDER BY receipt_id

获取主要类别的收据

SELECT receipts_body.receipt_id,items.id,items.title FROM receipts
LEFT JOIN items ON items.id = receipts_body.item_id
WHERE receipt_id IN (SELECT receipt_id FROM receipt_body WHERE item_id = 771013)
ORDER BY receipt_id

获取小类收据

SELECT receipts_body.receipt_id,items.id,items.title FROM receipts
LEFT JOIN items ON items.id = receipts_body.item_id
WHERE receipt_id IN (SELECT receipt_id FROM receipt_body WHERE item_id = 771012)
ORDER BY receipt_id

相关问题