统计常用sql

1.gm_answer_question 表

2.统计表中的type=0对应的type=1的记录数 

SELECT 
  B.main_id,
  B.dt,
  COUNT(A.TYPE) 
FROM
  (SELECT 
    aq.main_id,
    t.subject_code,
    class.level_code,
    DATE_FORMAT(aq.create_time, '%Y-%m-%d') dt 
  FROM
    gm_answer_question aq,
    gm_teacher t,
    gm_class class,
    gm_school school 
  WHERE aq.TYPE = 0 
    AND aq.school_id = t.school_id 
    AND aq.receiver_id = t.user_id 
    AND aq.class_id = class.id 
    AND aq.delete_flag = 0 
    AND t.delete_flag = 0 
    AND class.delete_flag = 0 
    AND school.delete_flag = 0 
    AND school.id = aq.school_id 
    AND school.name LIKE CONCAT('%', '101', '%') 
    AND aq.create_time > STR_TO_DATE('2015-03-29', '%Y-%m-%d') 
    AND aq.create_time < STR_TO_DATE('2015-04-07', '%Y-%m-%d') 
  GROUP BY main_id) B 
  LEFT JOIN gm_answer_question A 
    ON B.main_id = A.main_id 
    AND A.TYPE = 1 
    AND A.delete_flag = 0 
GROUP BY B.main_id 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值