日期:2014-05-17 浏览次数:20567 次
USE test
GO
-->生成表tb
if object_id('tb') is not null
drop table tb
Go
Create table tb([Station] int,[ObserveDate] datetime,[AverTemperature] smallint)
Insert into tb
Select 50136,'1958-1-1',-315
Union all Select 50136,'1958-1-2',-305
Union all Select 50136,'1958-1-3',-294
Union all Select 50136,'1958-1-4',-270
Union all Select 50136,'1958-1-5',-181
Union all Select 50136,'1958-1-6',-194
Union all Select 50136,'1958-1-7',-271
Union all Select 50136,'1958-1-8',-334
Union all Select 50136,'1958-1-9',-324
Union all Select 50136,'1958-1-10',-349
Union all Select 50136,'1958-1-11',-385
Union all Select 50136,'1958-1-12',-383
Union all Select 50136,'1958-1-13',-355
Union all Select 50136,'1958-1-14',-354
Union all Select 50136,'1958-1-15',-287
Union all Select 50136,'1958-1-16',-282
Union all Select 50136,'1958-1-17',-339
Union all Select 50136,'1958-1-18',-359
Union all Select 50136,'1958-1-19',-356
Union all Select 50136,'1958-1-20',-349
Union all Select 50136,'1958-1-21',-297
Union all Select 50136,'1958-1-22',-279
Union all Select 50136,'1958-1-23',-314
Union all Select 50136,'1958-1-24',-279
Union all Select 50136,'1958-1-25',-294
Union all Select 50136,'1958-1-26',-290
Union all Select 50136,'1958-1-27',-332
go
-------- 1.
SELECT
a.Station AS [站点]
,COUNT(1) AS [次数]
FROM
tb AS a
,tb AS b
,tb AS c
WHERE a.ObserveDate=b.ObserveDate-1
AND b.ObserveDate=c.ObserveDate-1
AND a.AverTemperature<-350
AND b.AverTemperature<-350
AND c.AverTemperature<-350
GROUP BY
a.Station
/*
站点 次数
----------- -----------
50136&nbs