select d.* from yourtable a right join 
( select * from (
         (select id,day from yourtable group by id,day having count(*)<24) a 
         cross join 
         (select 1 union select 2 ...union select 24) b
         ) c
) d
on a.id=d.id and a.day=d.day
where a.id is null or a.day is null

解决方案 »

  1.   

    应该是
    select 1 as hour union select 2 as hour  ...union select 24 as houron a.id=d.id and a.day=d.day and a.hour=d.hour
    where a.id is null or a.day is null
      

  2.   

    where a.id is null or a.day is null or a.hour is null
      

  3.   

    select c.* from
    (
    select id,day,hour from
    (select distinct  id,day  from tablename) as a cross join
    (select 1 as hour union select 2 as hour  ...union select 24 as hour
    ) as b
    ) as c left join tablename d
    on c.id=d.id
    and c.day=d.day
    and c.hour=d.hour
    where d.hour is null
      

  4.   

    Yang_(扬帆破浪)的语句是对的
    谢谢coowoo(一日一日) 的参与