我需要从mysql常绿周期(total-some prmo periods)获取一些数据;
SELECT SUM(view) AS tUniquePageViews FROM store_report_per_day WHERE tpi = 'SE0541' AND YEAR(trxDate) = '2018'
总计:462
SELECT SUM(view) AS tUniquePageViews FROM store_report_per_day WHERE tpi = 'SE0541' AND trxDate >= '2017-03-03' AND trxDate <= '2017-09-12'
0
SELECT SUM(view) AS tUniquePageViews FROM store_report_per_day WHERE tpi = 'SE0541' AND trxDate >= '2018-09-11' AND trxDate <= '2019-01-03'
5
SELECT SUM(view) AS tUniquePageViews FROM store_report_per_day WHERE tpi = 'SE0541' AND trxDate >= '2018-07-01' AND trxDate <= '2018-09-04'
218
SELECT SUM(view) AS tUniquePageViews FROM store_report_per_day WHERE tpi = 'SE0541' AND trxDate >= '2018-08-01' AND trxDate <= '2018-08-18'
4
SELECT SUM(view) AS tUniquePageViews FROM store_report_per_day WHERE tpi = 'SE0541' AND trxDate >= '2018-07-01' AND trxDate <= '2018-07-31'
4
SELECT SUM(view) AS tUniquePageViews FROM store_report_per_day WHERE tpi = 'SE0541' AND trxDate >= '2018-06-15' AND trxDate <= '2018-06-30'
2
现在我需要获取total-(all periods)我的查询是
SELECT SUM(view) AS tUniquePageViews FROM store_report_per_day WHERE tpi = 'SE0541' AND 1 AND (trxDate < '2018-09-11' OR trxDate > '2018-10-25') AND (trxDate < '2018-07-01' OR trxDate > '2018-09-04') AND (trxDate < '2018-08-01' OR trxDate > '2018-08-18') AND (trxDate < '2018-07-01' OR trxDate > '2018-07-31') AND (trxDate < '2018-06-15' OR trxDate > '2018-06-30')
我想要的输出是
462-0-5-218-4-4-2=229但我得到237
当我对1或2个日期范围进行查询时,它会显示很好的结果,但总的来说不会。
我的问题是什么。
2条答案
按热度按时间lp0sw83n1#
为什么不把所有的查询合并在一起得到最终的总和呢?
bvjxkvbb2#
您可以尝试使用条件聚合