(一)、根据teacher_no统计星期的上课数-创新互联
做网站、滕州网站设计,以传统方式定制建设网站,并提供域名空间备案等一条龙服务,秉承以专业、用心的态度为用户提供真诚的服务。我们深信只要达到每一位用户的要求,就会得到认可,从而选择与我们长期合作。这样,我们也可以走得更远!/>
- -- 解法一
- SELECT
- t1.teacher_no,
- (CASE WEEK WHEN '1' THEN keshu ELSE 0 END ) 礼拜一,
- (CASE WEEK WHEN '2' THEN keshu ELSE 0 END ) 礼拜二,
- (CASE WEEK WHEN '3' THEN keshu ELSE 0 END ) 礼拜三
- FROM
- (
- SELECT
- teacher_no,
- WEEK,
- COUNT(1) AS keshu
- FROM teach
- GROUP BY teacher_no,WEEK
- )t1
- GROUP BY t1.teacher_no;
-
-
- -- 解法二 就是count()函数作用
- SELECT
- t1.teacher_no,
- (CASE WEEK WHEN '1' THEN keshu ELSE 0 END ) 礼拜一,
- (CASE WEEK WHEN '2' THEN keshu ELSE 0 END ) 礼拜二,
- (CASE WEEK WHEN '3' THEN keshu ELSE 0 END ) 礼拜三
- FROM
- (
- SELECT
- t.teacher_no,
- t.WEEK,
- COUNT(t.keshu) AS keshu
- FROM
- (
- SELECT
- teacher_no,
- WEEK,
- '1' keshu
- FROM teach )t
- GROUP BY teacher_no,WEEK
- )t1
- GROUP BY t1.teacher_no
- ;
分享标题:(一)、根据teacher_no统计星期的上课数-创新互联
当前地址:http://ybzwz.com/article/cojsgp.html