我有以下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所有权给了我第1行和第3行,但不是第二行。这是我的确切查询,任何帮助将不胜感激:
$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";
答案 0 :(得分:1)
只需在group by子句中添加类型即可。由于您没有提供列名称,我猜想会像:
GROUP BY t.type, u.ownership