draxq02664 2018-07-13 08:28
浏览 64

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

I'm trying to separate different product category in a receipt so that I can have different query for the MAJOR category and the MINOR category using MYSQL.

MAJOR has an item code of 771013 and MINOR has an item code of 771012. That being said, I also want to get the items that have been ordered in each check.

enter image description here

Here is my desired output.

enter image description here enter image description here

I'm using MYSQL and PHPExcel on how to do this. Can you give me hints on how to do my query? Is this possible with the formula of vlookup with PHPExcel?

  • 写回答

1条回答 默认 最新

  • dsx58940 2018-07-13 10:25
    关注

    To get the items in receipts

    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
    

    To get the receipts with MAJOR category

    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
    

    To get the receipts with MINOR category

    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
    
    评论

报告相同问题?

悬赏问题

  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度