tbl_usersSQL條件顯示記錄
u_id | u_type | u_first_name
1 U I_am_user
2 E I_am_emp
3 E I_am_emp2
tbl_order
o_id | u_id | e_id | o_status | pay_status
1 1 0 pending Unpaid
2 1 2 pick Paid
3 1 0 pending Unpaid
4 1 3 Pick paid
我嘗試此查詢或者顯示用戶和EMP名
SELECT o.*, a.u_first_name as user, b.u_first_name as emp
FROM `tbl_order` AS o
LEFT JOIN tbl_users AS a ON a.u_id = o.u_id
LEFT JOIN tbl_users AS b ON b.u_id = o.e_id
o_id | u_id | e_id | user | emp | pay_staus
我們怎麼將給條件(順序其他1)先顯示未付款(pay_status
)記錄 然後e_id=0
記錄然後全部休息?
你就不能'ORDER BY pay_status DESC'? – hims056
我試過了,但我們如何給下一個條件? 未付 e_id = 0 – Anu
下一個條件?哪一個? – hims056