(一)、根据teacher_no统计星期的上课数-创新互联


做网站、滕州网站设计,以传统方式定制建设网站,并提供域名空间备案等一条龙服务,秉承以专业、用心的态度为用户提供真诚的服务。我们深信只要达到每一位用户的要求,就会得到认可,从而选择与我们长期合作。这样,我们也可以走得更远!/>(一)、根据teacher_no统计星期的上课数

  1. -- 解法一
  2. SELECT
  3.   t1.teacher_no,
  4.   (CASE WEEK WHEN '1' THEN keshu ELSE 0 END ) 礼拜一,
  5.   (CASE WEEK WHEN '2' THEN keshu ELSE 0 END ) 礼拜二,
  6.   (CASE WEEK WHEN '3' THEN keshu ELSE 0 END ) 礼拜三
  7. FROM
  8. (
  9.     SELECT
  10.       teacher_no,
  11.       WEEK,
  12.       COUNT(1) AS keshu
  13.       FROM teach
  14.   GROUP BY teacher_no,WEEK
  15.  )t1
  16.   GROUP BY t1.teacher_no;


  17. -- 解法二 就是count()函数作用
  18. SELECT
  19.   t1.teacher_no,
  20.   (CASE WEEK WHEN '1' THEN keshu ELSE 0 END ) 礼拜一,
  21.   (CASE WEEK WHEN '2' THEN keshu ELSE 0 END ) 礼拜二,
  22.   (CASE WEEK WHEN '3' THEN keshu ELSE 0 END ) 礼拜三
  23. FROM
  24. (
  25.   SELECT
  26.   t.teacher_no,
  27.   t.WEEK,
  28.   COUNT(t.keshu) AS keshu
  29.   FROM
  30.       (
  31.       SELECT
  32.       teacher_no,
  33.       WEEK,
  34.       '1' keshu
  35.       FROM teach )t
  36.   GROUP BY teacher_no,WEEK
  37.     )t1
  38. GROUP BY t1.teacher_no
  39. ;

分享标题:(一)、根据teacher_no统计星期的上课数-创新互联
当前地址:http://ybzwz.com/article/cojsgp.html