sql分组函数例子

好久没写分组函数了,突然用到了,在这里总结一下,下次再写就一点问题没有了。

select count(*) as couponCount,d.id as serviceId,d.name as serviceName,g.id_c couponId,f.name couponName
  from t_member_card             a,
       t_member_card_cstm        b,
       t_member_cat_coupon_rel_c c,
       t_coupon                  d,
       t_coupon_cstm             e,
       t_coupon_rel              f,
       t_coupon_rel_cstm         g
 where c.t_member_cd973er_card_ida = a.id
   and c.t_member_c474apon_rel_idb = f.id
   and a.id = b.id_c
   and d.id = e.id_c
   and f.id = g.id_c
   and f.deleted='0'
   and a.deleted='0'
   and d.deleted='0'
   and g.t_coupon_id_c = d.id
   and a.name = '00AE29A3EF' group by d.id,d.name,g.id_c,f.name; ---------》这个地方要注意,要把查询的字段全部放在group by 后面,否则会报错的

猜你喜欢

转载自576017120.iteye.com/blog/1502767