表good(id,num,color,size,money)  
里面有这些数据
num color size money
1     1     1    50
1     1     2    50
1     1     2    50
1     2     3    40
1     2     3    50
1     2     3    60
我以num + color + size 分组,得出这种形式的结果:
num  color  size  totalmoney totalCount
1      1      1      50         1
1      1      2      100        2
1      2      3      150        3 这条sql语句怎么写?????????  另外,如果大侠用过hql,用hql也帮我写下???先谢了

解决方案 »

  1.   

    select num,color,size,sum(money),count(*)
    from tt group by num,color,size
      

  2.   

    select num,color,size,sum(money) as totalmoney ,count(*) as totalCount
    from tt group by num,color,size
      

  3.   

    select 
      num,
      color,
      size,
      sum(money) as totalmoney,
      count(*) as totalCount 
    from good 
    group by num,color,size
      

  4.   

    接个地方求语句
    num size
    1    l
    2    xl
    3    s
    -----------
    size  color
     s     red
     s     blue
     s     black
     l     white
     l     orange
    xl     yellow
    ------------
    两个表由size字段连接,但color只取前两种,这个如何写啊?
      

  5.   

    select num,color,size,sum(money) as totalmoney ,count(1) as totalcount from tblname group by num,color,size