0
我需要比较同一表中同一列中的2017年和2016年之间的数据。如何比较同一表中同一列中的数据
现在我用2个查询:
第一次查询:
SELECT
SUM(a.netamt) AS netamt2017, b.store_name, c.budget
FROM
site_sales a
JOIN
site_store b ON b.storenum = a.storenum
JOIN
site_kpimthslsbgt c ON b.storenum = c.storenum
WHERE
c.busidate = '2017-01'
AND a.busidate >= '2017-01-01'
AND a.busidate <= '2017-01-15'
GROUP BY
a.storenum
这对于找到netamt 2017年
第二查询:
SELECT
SUM(a.netamt) AS netamt2016, b.store_name, c.budget
FROM
site_sales a
JOIN
site_store b ON b.storenum = a.storenum
JOIN
site_kpimthslsbgt c ON b.storenum = c.storenum
WHERE
c.busidate = '2017-01'
AND a.busidate >= '2016-01-01'
AND a.busidate <= '2016-01-15'
GROUP BY
a.storenum
这种寻找“Netamt 2016 ”。
我需要这2个查询结合起来,形成该表:
Here is example for the output
非常感谢您的回答。它工作得很好! :) –