zoukankan      html  css  js  c++  java
  • 统计 武胜

    mh:工时 mhtype:工时类型(6种)

    字段:userid mhtype mh
      001 1 5
      001 1 3
      001 2 4
      001 3 9
      002 5 5
      002 6 7
      002 3 4
      002 3 9

    要求统计出每个人每一类工时的总合
    结果要求如下格式
    userid mhtype1 mhtype2 mhtype3 mhtype4 mhtype5 mhtype6 allmh
    001 8 4 9 0 0 0 21
    002 0 0 13 0 5 7 25

    createtable lk4( userid mediumint(3) unsigned zerofill notnull, mhtype intnotnull, mh intnotnull); insertinto lk4 values (001,1,5), (001,1,3), (001,2,4), (001,3,9), (002,5,5), (002,6,7), (002,3,4), (002,3,9); select userid, sum((casewhen mhtype=1then mh else0end )) as'mhtype1', sum((casewhen mhtype=2then mh else0end )) as'mhtype2', sum((casewhen mhtype=3then mh else0end )) as'mhtype3', sum((casewhen mhtype=4then mh else0end )) as'mhtype4', sum((casewhen mhtype=5then mh else0end )) as'mhtype5', sum((casewhen mhtype=6then mh else0end )) as'mhtype6', sum(mh) as'allmh'from lk4 groupby userid;



    结果:

    +--------+---------+---------+---------+---------+---------+---------+-------+
    | userid | mhtype1 | mhtype2 | mhtype3 | mhtype4 | mhtype5 | mhtype6 | allmh |
    +--------+---------+---------+---------+---------+---------+---------+-------+
    | 001 | 8 | 4 | 9 | 0 | 0 | 0 | 21 |
    | 002 | 0 | 0 | 13 | 0 | 5 | 7 | 25 |
    +--------+---------+---------+---------+---------+---------+---------+-------+
    2 rows in set (0.00 sec)

  • 相关阅读:
    Linux install
    plafrom library
    lua 线程
    plafrom SDK
    CSS中的focus-within伪类选择器
    网站打开速度优化_如何提高网页访问速度技巧方法总结
    网页预加载_骨架屏Skeleton Screen的实现
    SASS简介及使用方法
    什么是BFC布局——浅析BFC布局的概念以及作用
    JAVA面试题(九):JVM
  • 原文地址:https://www.cnblogs.com/zeroone/p/2723360.html
Copyright © 2011-2022 走看看