现在请教一个问题,是关于查询的,现在有两个表,stationinfo,里面存放的是台站信息,还有另一个表是jw_daycount,存放的是每天24小时每小时的统计数据,这两张表里存放的记录分别如下:
stationinfo表:
   jwstation           jwnumber
      北京        X3510064
   天津        X3120068
   郑州        X3020023
   上海        X3012005
jw_daycount表:
    
      jwstation           jwnumber      jwdatetime   jwcount
      北京        X3510064    2010-02-01 00    60
   天津        X3120068    2010-02-01 00    52
   上海        X3012005    2010-02-01 00    72
      北京        X3510064    2010-02-01 01    60
   天津        X3120068    2010-02-01 01    52
   上海        X3012005    2010-02-01 01    72
       ...
       ...
      北京         X3510064    2010-02-01 23    60
   天津        X3120068    2010-02-01 23    52
   上海        X3012005    2010-02-01 23    72在jw_daycount表中,存放的是三个地方数据,没有郑州这个地方数据,怎样根据station_info表来查询出没有郑州这个地方没有数据呢?谢谢,请教高手

解决方案 »

  1.   

    select
      *
    from
      jw_daycount t
    where
      not exists(select 1  from stationinfo where jwstation=t.jwstation)
      

  2.   

    select * from stationinfo t where not exists(select 1 from jw_daycount where jwstation=t.jwstation)
      

  3.   

    select * from stationinfo s where not exists(select 1 from jw_daycount where jwstation=s.jwstation)
      

  4.   

    select a.* from stationinfo a left join jwstation b on a.jwstation =b.jwstation 
    where b.jwstation is null
      

  5.   

    很感谢你的回复.我想进一步问
    那如果在jw_daycount表中查询每小时是否存在郑州的数据该怎么做呢?
      

  6.   

    很感谢你的回复.我想进一步问 
    那如果在jw_daycount表中查询每小时是否存在郑州的数据该怎么做呢?
      

  7.   

    select 1 from jw_daycount
    where jwstation='郑州'
    group by convert(varchar(10),jwdatetime,120)
    having count(1)=24
    有结果就表示郑州一天24小时都有数据,否则不一定
      

  8.   

    大哥,你的方法很不错,但是要按照stationinfo 来显示每小时没有相关地方的统计数据该怎么办呢?
      

  9.   

    ??
    select * from tationinfo a
    where (select count(jwstation) from jw_daycount
    where jwstation=a.jwstation)<24