gpt4 book ai didi

MYSQL 按列分组

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

我有以下 MYSQL 输出

Type        | Unit | Model       |Ownership         
-----------------------------------------
Drill | BM70 | DD110 | owned
Drill | BM81 | DD110 | owned
Light Plant | X652 | 20 KW Tower | owned
Light Plant | LT12 | 20 KW Tower | rental
Light Plant | LT13 | 20 KW Tower | rental
Light Plant | G242 | 20 KW Tower | rental

我试图显示的是类型、型号和所有权,除非我获得所有权,否则它们都可以正常工作。我需要分解拥有和租赁之间的所有权,因此查询后显示的输出应如下所示

   Type        | Model        |Ownership         
------------------------------------
Drill | DD110 | owned
Light Plant | 20 KW Tower | owned
Light Plant | 20 KW Tower | rental

在 SQL 语句中,我使用 GROUP BY 所有权给了我第一行和第三行,但不是第二行。这是我的确切查询,任何帮助将不胜感激:

               $order = 'equipment_model_name';

$get_equipment = "SELECT * FROM
rbs_equipment_type t
INNER JOIN
rbs_equipment_model m
ON t.id = m.model_type_id
INNER JOIN
rbs_equipment_unit u
ON m.model_id = u.equipment_unit_model_id
GROUP BY u.ownership
ORDER BY $order";

最佳答案

只需在 group by 子句中添加类型即可。由于您没有提供列名称,我会猜测类似:

GROUP BY t.type, u.ownership

关于MYSQL 按列分组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24702331/

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