select 
    t.* 
from 
    tab t
where 
    (t.tot_pos+t.tot_neg)<(t.must_pos+t.must_neg)
and
    exists(select 
               1 
           from 
               tab a,tab b
           where 
               (a.tot_pos+a.tot_neg)<(a.must_pos+a.must_neg)
           and
               (b.tot_pos+b.tot_neg)<(b.must_pos+b.must_neg)
           and 
               datediff(mi,a.info_time,b.info_time)>10)

解决方案 »

  1.   

    select 1是什么意思?
    能解释一下这条SQL的意思么?
      

  2.   

    BACKUP_INFO_ID PROVINCE_ID INFO_TIME                                              SELF_POS           SELF_NEG           DISTR_POS          DISTR_NEG          TOT_POS            TOT_NEG            PLAN_POS           PLAN_NEG           PLAN_INPUT_POS     PLAN_INPUT_NEG     LOAD               ACCIDENT           INPUT_ACCIDENT     MUST_POS           MUST_NEG           MUST_ACCIDENT      
    -------------- ----------- ------------------------------------------------------ ------------------ ------------------ ------------------ ------------------ ------------------ ------------------ ------------------ ------------------ ------------------ ------------------ ------------------ ------------------ ------------------ ------------------ ------------------ ------------------ 
    3              1           2005-04-15 22:23:25.000                                35.000             78.000             90.000             99.000             65.000             78.000             87.000             88.000             89.000             56.000             67.000             45.000             78.000             600.000            33.000             678.000
    4              2           2005-04-15 22:23:25.000                                78.000             55.000             66.000             77.000             88.000             99.000             242.000            67.000             65.000             65.000             78.000             89.000             99.000             2345.000           79.000             58.000
    6              1           2005-04-16 22:00:00.000                                78.000             78.000             78.000             78.000             78.000             78.000             78.000             78.000             NULL               NULL               NULL               NULL               NULL               5555.000           5555.000           NULL(所影响的行数为 3 行)这是查询后的结果
    可不可以让字段PROVINCE_ID不重复?类似于DISTINCT?