我几乎从不使用MYSQL,所以请原谅基本问题但是......
是否可以在MYSQL中组合2个查询并发送不同的结果集?除了request_date
值不同之外,我有以下2个相同的查询。运行第一个提供100
并运行第二个提供200
。是否有可能将它们组合在一起并分别得到100和200?
我不是说我想要回300,我仍然希望分别取回每天的总数。这可以在一个查询中完成吗?
SELECT SUM(revenue - spend) as total_profit FROM `profit_by_campaign` WHERE campaign_name = 'myCoolCampaign' AND request_date = '2017-11-03'
SELECT SUM(revenue - spend) as total_profit FROM `profit_by_campaign` WHERE campaign_name = 'myCoolCampaign' AND request_date = '2017-11-02'
答案 0 :(得分:3)
尝试使用GROUP BY:
SELECT request_date, SUM(revenue - spend) as total_profit
FROM `profit_by_campaign`
WHERE campaign_name = 'myCoolCampaign'
AND (request_date = '2017-11-03' OR request_date = '2017-11-02')
GROUP BY request_date