gpt4 book ai didi

mysql - 在 mysql 连接查询中需要帮助 - codeigniter

转载 作者:行者123 更新时间:2023-11-29 11:05:10 24 4
gpt4 key购买 nike

我在 mysql 中有一个表,其中包含以下数据

[代码]表名测试

Assettype   Serial_No     Status            location    
Mouse 123456 In Stock chennai
Mouse 98765 Allocated chennai
Keyboard 23498 In Stock bangalore
Keyboard 45646 Allocated bangalore
Mouse 234234 Decommisioned hyderabad

我正在寻找一个 mysql 查询,它将给出下面提到的输出

Assettype              In Stock    Allocated    Decommisioned       Location  
Mouse 1 1 0 chennai
Keyboard 1 1 0 bangalore
Mouse 0 0 1 hyderabad

请帮忙

最佳答案

您可以对 Assets 类型和位置进行分组并查找如下计数:

select 
assettype,
sum(status = 'In Stock') In_stock,
sum(status = 'Allocated') Allocated,
sum(status = 'Decommisioned') Decommisioned,
location
from test
group by assettype, location;

关于mysql - 在 mysql 连接查询中需要帮助 - codeigniter,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41523356/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com