答案 0 :(得分:2)
INNER JOIN可以胜任。
SELECT
WindowsTable.Date,
ABS(WindowsTable.Sold - MacTable.Sold) absoluteDifference
FROM
(SELECT
*
FROM producttable
WHERE Products = 'Windows') WindowsTable
INNER JOIN
(
SELECT
*
FROM producttable
WHERE Products = 'Mac' ) MacTable
ON WindowsTable.Date = MacTable.Date;
答案 1 :(得分:1)
尝试在日期使用INNER JOIN重塑您的查询:
SELECT macs_sales.Date, (MacsSold - WindowsSold) AS sales_difference
FROM
(
SELECT Date, Sold as MacsSold
FROM computer_sales
WHERE Products="Mac"
) macs_sales
INNER JOIN
(
SELECT Date, Sold as WindowsSold
FROM computer_sales
WHERE Products="Windows"
) windows_sales
ON macs_sales.Date = windows_sales.Date