2014-07-11 236 views
0

我有以下MYSQL輸出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 

我想顯示的類型,型號和ownerhship除非我得到所有權的正常工作。我要分手所有權之間自有和租用的,所以我的查詢後顯示的輸出應該看起來像

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

在我使用GROUP BY所有權給我的第1和第3行,但不是第二個SQL語句。這裏是我的確切查詢,任何幫助將不勝感激:

   $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"; 

回答

1

只需在group by子句中添加類型。既然你沒有提供列名,我會猜這樣的:

GROUP BY t.type, u.ownership 
+0

薄荷!感謝芽 – Owen