如何在PHP MySQL中减去两个查询计数

时间:2019-04-04 09:30:20

标签: mysql

MySQL查询1-

SELECT assets.name, models.model_number,
      COUNT(CASE when (month(DATE_ADD(purchase_date, INTERVAL 1461 DAY)) BETWEEN 2 AND 4) AND Year(DATE_ADD(purchase_date, INTERVAL 1461 DAY))<=year(curdate()) THEN 1 end)      
   as total_count FROM assets, models WHERE assets.model_id = models.id AND status_id=30 or status_id=1

MySQL Query2-

SELECT assets.name, models.model_number,
      COUNT(CASE when (month(DATE_ADD(purchase_date, INTERVAL 1461 DAY)) BETWEEN 2 AND 4) AND Year(DATE_ADD(purchase_date, INTERVAL 1461 DAY))<=year(curdate()) THEN 1 end)      
   as total_count FROM assets, models WHERE assets.model_id = models.id AND status_id=26 or status_id=1

现在我想将query1减去query2。有人可以在这里帮助我吗?

首次查询-结果

名称|型号| Total_Count

Windows笔记本电脑E7440 12

第二次查询-结果

名称|型号| Total_Count

Windows笔记本电脑E7440 1

现在我想要这样的东西...。

名称|型号|总计数|待处理(Query1-Query2)

Windows笔记本电脑E7440 12 11

0 个答案:

没有答案