• sql分组数据去重


    #分组获得每个机柜里服务器占用的机架总数,如552807e6-b428-4184-b219-ae368c68ddb3占用4个
    
    mysql> select cabinet_uuid, count(host_uuid) from rack where not host_uuid is NULL group by cabinet_uuid;
    +--------------------------------------+------------------+
    | cabinet_uuid                         | count(host_uuid) |
    +--------------------------------------+------------------+
    | 552807e6-b428-4184-b219-ae368c68ddb3 |                4 |
    | 55ce78c0-1c2c-4d34-b383-4028fe45a2fa |                7 |
    | 6662c7d9-1cd7-426b-8616-5190c434bc1e |               21 |
    | 6b293326-00d0-4d59-9fd9-5c18273fcbcb |                2 |
    | 77b86411-93d8-4af8-afd1-08ee5f90435d |               11 |
    | 8f233310-cf75-457b-b7c4-4476e48cfab2 |                8 |
    | 92da441c-54bf-4e9f-8b96-4e53cdb6dee4 |               19 |
    | a3b6ebdf-7c6b-4571-b079-e7bcef662c4e |               14 |
    | a7d76dd6-bbf9-4cf8-a1f9-40697a95f03f |               17 |
    | e3b18a11-b542-4dbd-955f-f2d2f38e901b |               15 |
    +--------------------------------------+------------------+
    
    #机柜552807e6-b428-4184-b219-ae368c68ddb3里有2u服务器1台,1u服务器2台,也就是说2u服务器有2条一样的host_uuid,使用DISTINCT去重,得到每机柜准确的设备数
    
    mysql> select cabinet_uuid, count(DISTINCT host_uuid) from rack where not host_uuid is NULL group by cabinet_uuid;
    +--------------------------------------+---------------------------+
    | cabinet_uuid                         | count(DISTINCT host_uuid) |
    +--------------------------------------+---------------------------+
    | 552807e6-b428-4184-b219-ae368c68ddb3 |                         3 |
    | 55ce78c0-1c2c-4d34-b383-4028fe45a2fa |                         4 |
    | 6662c7d9-1cd7-426b-8616-5190c434bc1e |                        14 |
    | 6b293326-00d0-4d59-9fd9-5c18273fcbcb |                         2 |
    | 77b86411-93d8-4af8-afd1-08ee5f90435d |                         7 |
    | 8f233310-cf75-457b-b7c4-4476e48cfab2 |                         5 |
    | 92da441c-54bf-4e9f-8b96-4e53cdb6dee4 |                        12 |
    | a3b6ebdf-7c6b-4571-b079-e7bcef662c4e |                         9 |
    | a7d76dd6-bbf9-4cf8-a1f9-40697a95f03f |                        13 |
    | e3b18a11-b542-4dbd-955f-f2d2f38e901b |                        11 |
    +--------------------------------------+---------------------------+
    
    
  • 相关阅读:
    ESP32环境搭建(arduino)
    uPyCraftIDE的介绍以及使用
    ESP32项目汇总
    MicroPython固件烧写
    Server 架构
    base家族在线解密工具
    第1年2月24日 iOS相机旋转问题 为什么UIimage.ciimage值为空
    第1年2月23日 du -sh * | sort -n 统计当前文件夹(目录)大小,并按文件大小排序
    第1年2月14日 mac 运行java
    第1年2月10日 检查iOS app证书过期时间信息
  • 原文地址:https://www.cnblogs.com/liujitao79/p/6306121.html
Copyright © 2020-2023  润新知