两个时间段内存在的 IDS 的不同计数
DISTINCT COUNT OF IDS PRESENT IN TWO TIME PERIODS
我想了解上一年和当前一年回顾中售出汽车的员工的不同数量。以下示例中的日期结束于 2018 年 11 月 18 日。当 运行 只有一个 'between and' 子句但不满足两个条件时,我可以提取计数。
SELECT COUNT(UNIQUE(EMPLOYEE_ID))
FROM SALES_TABLE_123
WHERE SOLD_ITEM = 'CARS'
AND (SELL_DATE) BETWEEN ('2017-11-19') AND ('2018-11-19')
AND (SELL_DATE) BETWEEN ('2016-11-18') AND ('2017-11-18');
SELECT COUNT(UNIQUE(LY.EMPLOYEE_ID))
FROM SALES_TABLE_123 LY
inner join
SALES_TABLE_123 TY
on LY.EMPLOYEE_ID=TY.EMPLOYEE_ID
WHERE LY.SOLD_ITEM = 'CARS'
AND TY.SOLD_ITEM='CARS'
AND TY.SELL_DATE BETWEEN ('2017-11-19') AND ('2018-11-19')
AND LY.SELL_DATE BETWEEN ('2016-11-18') AND ('2017-11-18');
我想了解上一年和当前一年回顾中售出汽车的员工的不同数量。以下示例中的日期结束于 2018 年 11 月 18 日。当 运行 只有一个 'between and' 子句但不满足两个条件时,我可以提取计数。
SELECT COUNT(UNIQUE(EMPLOYEE_ID))
FROM SALES_TABLE_123
WHERE SOLD_ITEM = 'CARS'
AND (SELL_DATE) BETWEEN ('2017-11-19') AND ('2018-11-19')
AND (SELL_DATE) BETWEEN ('2016-11-18') AND ('2017-11-18');
SELECT COUNT(UNIQUE(LY.EMPLOYEE_ID))
FROM SALES_TABLE_123 LY
inner join
SALES_TABLE_123 TY
on LY.EMPLOYEE_ID=TY.EMPLOYEE_ID
WHERE LY.SOLD_ITEM = 'CARS'
AND TY.SOLD_ITEM='CARS'
AND TY.SELL_DATE BETWEEN ('2017-11-19') AND ('2018-11-19')
AND LY.SELL_DATE BETWEEN ('2016-11-18') AND ('2017-11-18');