加入一个类别

时间:2014-01-27 02:19:13

标签: sql join

假设我有温度记录,其中包含以下形式的记录:

  

年,日,温度

我希望每年的第一天温度超过100℃。 现在我可以使用下面的一组查询得到它...有没有办法将它组合成一个查询?

select day,year from t
where temperature>100 and year=2000
order by day limit 1;

select day,year from t
where temperature>100 and year=2001
order by day limit 1;

select day,year from t
where temperature>100 and year=2002
order by day limit 1;

select day,year from t
where temperature>100 and year=2003
order by day limit 1;

1 个答案:

答案 0 :(得分:2)

select year, min(day) as first_day
from t
where temperature > 100
group by year
order by year