我给大家一组测试数据:编号  日期        最大电压   最大电压日期      最小电压   最小电压日期
1001  2006-06-21  235.3      2006-06-21 22:30  207.7      2006-06-21 18:31
1001  2006-06-22  235.8      2006-06-22 16:11  218.6      2006-06-22 14:17
1001  2006-06-25  238.1      2006-06-25 08:17  226.9      2006-06-25 23:49我需要得到的结果:编号  日期        最大电压   最大电压日期      最小电压   最小电压日期
1001  无          238.1      2006-06-25 08:17  207.7      2006-06-21 18:31请各位高手帮帮忙啊!分数不够再加!

解决方案 »

  1.   


    select top 1  a,b='无',c=(select max(c) from test),d = (select d from test where c = (select max(c) from test)),e=(select min(e) from test),f = (select f from test where e = (select min(e) from test))    from test  
    a,b,c,d,e,f分别对应你上面的字段
      

  2.   

    一个SQL语句有难度,使用存储过程,在存储过程中处理。
      

  3.   

    create table t(编号 int,  日期 datetime,        最大电压 decimal(10,1),   最大电压日期 datetime,      最小电压 decimal(10,1),    最小电压日期 datetime)
    insert t select 1001,  '2006-06-21',  235.3,      '2006-06-21 22:30',  207.7,      '2006-06-21 18:31'
    union all select 1001,  '2006-06-22',  235.8,      '2006-06-22 16:11',  218.6,      '2006-06-22 14:17'
    union all select 1001,  '2006-06-25',  238.1,      '2006-06-25 08:17',  226.9,      '2006-06-25 23:49'select distinct A.编号,N'无' [日期],A.最大电压,
    (select top 1 convert(varchar(16),最大电压日期,120) from t where 最大电压=A.最大电压) [最大电压日期],
    B.最小电压 ,
    (select top 1 convert(varchar(16),最小电压日期,120) from t where 最小电压=B.最小电压) [最小电压日期]
    from t
    join (select 编号,max(最大电压) [最大电压] from t group by 编号) A on A.编号=t.编号 
    join (select 编号,min(最小电压) [最小电压] from t group by 编号) B on B.编号=t.编号drop table t
    /*
    编号          日期   最大电压         最大电压日期           最小电压         最小电压日期           
    ----------- ---- ------------ ---------------- ------------ ---------------- 
    1001        无    238.1        2006-06-25 08:17 207.7        2006-06-21 18:31
    */
      

  4.   

    Select * From (Select Top 1 * From 
    (Select MaxPressure,MaxDate From test 
    where CurrentlyDate >= '2006-01-01' 
    and CurrentlyDate <= '2006-12-31') as myMaxTest Order by MaxPressure Desc) as MaxTest,
    (Select Top 1 * From 
    (Select MinPressure,MinDate From test 
    where CurrentlyDate >= '2006-01-01' 
    and CurrentlyDate <= '2006-12-31') as myMinTest Order by MinPressure) as MinTest
      

  5.   

    我估计你是要在一定的范围内检索数据,所以先缩小检索的范围,然后在此范围内再筛选数据我觉得这种筛选最好不要用SQL实现,用存储过程性能会好得多
      

  6.   

    axPressure  最大电压
    MaxDate     最大电压日期
    MinPressure 最小电压
    MinDate     最小电压日期用SQL要过滤二次数据,所以性能不太好,存储过程只用一次
    Select MaxPressure,MaxDate,MinPressure,MinDate From test 
    where CurrentlyDate >= '2006-01-01' 
    and CurrentlyDate <= '2006-12-31')
    至于编号和日期,你可以在输出的时候再加上
      

  7.   

    create table t(编号 int,  日期 datetime,        最大电压 decimal(10,1),   最大电压日期 datetime,      最小电压 decimal(10,1),    最小电压日期 datetime)
    insert t select 1001,  '2006-06-21',  235.3,      '2006-06-21 22:30',  207.7,      '2006-06-21 18:31'
    union all select 1001,  '2006-06-22',  235.8,      '2006-06-22 16:11',  218.6,      '2006-06-22 14:17'
    union all select 1001,  '2006-06-25',  238.1,      '2006-06-25 08:17',  226.9,      '2006-06-25 23:49'select distinct A.编号,N'无' [日期],A.最大电压,
    (select top 1 convert(varchar(16),最大电压日期,120) from t where 最大电压=A.最大电压) [最大电压日期],
    B.最小电压 ,
    (select top 1 convert(varchar(16),最小电压日期,120) from t where 最小电压=B.最小电压) [最小电压日期]
    from t
    join (select 编号,max(最大电压) [最大电压] from t group by 编号) A on A.编号=t.编号 
    join (select 编号,min(最小电压) [最小电压] from t group by 编号) B on B.编号=t.编号drop table t
    /*
    编号          日期   最大电压         最大电压日期           最小电压         最小电压日期           
    ----------- ---- ------------ ---------------- ------------ ---------------- 
    1001        无    238.1        2006-06-25 08:17 207.7        2006-06-21 18:31
    */佩服敬业精神  没的讲