表格结构
现在想按每小时取出一个ReadNumber(取每小时最小的) 由于是软件自动生成的数据 ReadDate数据类型是varchar
求具体写法 用的是sel server 2000
------解决方案--------------------
- SQL code
select * from tb as t where not exists(select 1 from tb where convert(varchar(13),ReadDate,120)=convert(varchar(13),ReadDate,120)and ReadNumber<t.ReadNumber)
------解决方案--------------------
- SQL code
select convert(decimal(18,12), replace(min(convert(char(13),readdate,120)+convert(varchar(18),ReadNumber)), min(convert(char(13),readdate,120)), '') )from tabgroup by convert(char(13),readdate,120)
------解决方案--------------------
- SQL code
select convert(varchar(10),ReadyDate,120) 日期,datepart(hh,ReadyDate) 小时,min(ReadNumber) ReadNumber from [表]group by convert(varchar(10),ReadyDate,120),datepart(hh,ReadyDate)