表数据如下cdate           ctime
2009-2-10        4
2009-2-11        5
2009-2-12        9
2009-2-10        5
2009-2-13        3
2009-2-14        2
2009-2-13        6想得到的结果是同一天的时间加起来大于8的数据,就下面显示的。cdate         ctime
2009-2-10     4
2009-2-10     5
2009-2-12     9
2009-2-13     3
2009-2-13     6求sql语句,谢谢了,下面的sql 语句出错
select sum(ctime) xtime,cdate from th_time where  xtime>8 group by cdate

解决方案 »

  1.   

     select sum(cdate) as cdate from  th_time group by  cdate  having sum(cdate)>8 
      

  2.   

    谢谢了,能不能讲下having语句的意思
      

  3.   


    SELECT S1.cdate,S1.ctime
    FROM YOURTABLE S1,(SELECT cdate FROM YOURTABLE GROUP BY CDDATE HAVING SUM(CTIME)>8 ) S2
    WHERE S1.cdate = S2.CDATE;
      

  4.   


    select 块是在where 块之后的,在where 中的xtime值此时根本就没有,当然报错正解一楼的
      

  5.   


    你对着你的要求,答案在一楼,就知道 是什么意思
    要详细google看