在一个中合并多个两个查询

时间:2016-01-03 20:47:53

标签: php mysql

我有3个独立工作查询,我怎么能,但他们作为一个

SELECT * , SUM(summa) AS papp9 FROM rent WHERE liige_id = 9 AND date > NOW()
SELECT * , SUM(summa) AS papp8 FROM rent WHERE liige_id = 8 AND date > NOW()
SELECT * , SUM(summa) AS papp7 FROM rent WHERE liige_id = 7 AND date > NOW()

第一个查询结果如下所示: enter image description here

2 个答案:

答案 0 :(得分:2)

试试这个:

SELECT * , SUM(summa) AS papp FROM rent WHERE  date > NOW()
group by liige_id

答案 1 :(得分:1)

SELECT *, SUM(summa) AS papp9 
FROM rent 
WHERE liige_id IN (7,8,9) 
AND date > NOW()
GROUP BY liige_id