SQL(6)
!= 会排除null数据
select name from Customer where referee_id != 2 or referee_id is null;
交叉联结
交叉连接(CROSS JOIN)-CSDN博客
197. 上升的温度
select a.id
from weather
as a
cross join weather
as b
on datediff(a.recordDate ,b.recordDate ) = 1
where a.temperature > b.temperature ;
SELECT b.Id FROM Weather as a,Weather as b WHERE a.Temperature < b.Temperature and DATEDIFF(a.RecordDate,b.RecordDate) = -1;
1661. 每台机器的进程平均运行时间
SELECT a1.machine_id AS 'machine_id',
ROUND(AVG(a2.timestamp - a1.timestamp)
,3) AS 'processing_time'
FROM Activity AS a1
INNER JOIN Activity AS a2
ON a1.machine_id = a2.machine_id
AND a1.process_id = a2.process_id
AND a1.activity_type = 'start' AND a2.activity_type = 'end'
GROUP BY a1.machine_id