• 统计 武胜


    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 of函数实例
    Linux libenv 编译移植
    OpenTracing简单了解
    Byte Buddy简单学习
    JavaAgent简单学习
    TB2安装ubuntu16.04+kinetic的ROS包
    常用工具传送门
    ROS传送门
    结对第二次—文献摘要热词统计及进阶需求
    结对第一次—原型设计(文献摘要热词统计)
  • 原文地址:https://www.cnblogs.com/zeroone/p/2723360.html
Copyright © 2020-2023  润新知