第一臺員工查詢SQL連接和WHERE子句
id empName empEmail empSal active
====================================================
13 sadf [email protected] 233 1
12 checkout [email protected] 3 1
11 safg [email protected] 123 1
10 sdf [email protected] 4 1
9 sdaf [email protected] 3 1
8 asdf [email protected] 8 1
7 asdf [email protected] 8 1
6 asdf [email protected] 8 1
二表一致,如Emp_status
id emp_id EmpSalary active
=============================
5 4 156 1
4 2 156 1
3 2 555 1
2 1 200 0
1 1 1500 1
SELECT o.*
FROM employees as o
LEFT JOIN emp_status as emp ON emp.emp_id = o.id
WHERE (emp.active IS NULL OR (emp.active != 0))
GROUP BY o.id
ORDER BY o.id DESC
如果一致,如Emp_status有兩行一個有狀態1和其他具有狀態0,我們想要什麼,應該不能算如果我有零,它應該幫助執行。這怎麼可能?
你可以闡述多個表的條件我不明白嗎?你想跳過那些有0狀態的員工? –
請張貼預期結果。 – maSTAShuFu
如果要計數,請添加'SELECT count(o.id)AS cnt' –