类表
雇员表
1. We Have 2 tables 1 is employee and other is class
2. we have 4 records in employee table where emp\_id=as-1,as-2,as-3,as-4
3. we have 2 records in class table with emp\_id = as-1 or as-3 and timing= '3-4'
我们从雇员表中选择那些在时间上可用/免费的记录,比如as-2或as-3,因为as-1或as-3已经在3-4的类表中了。
发布于 2014-07-06 05:02:28
你还没有告诉我们很多,所显示的数据可能不完全有代表性。这两种方法都将返回employee 2和4 (&两者都将在MySQL或MSsql中工作):
SELECT
e.*
FROM employee e
LEFT JOIN class c
ON e.emp_id = c.emp_id
WHERE (c.timing <> '3-4'
OR c.timing IS NULL)
;
SELECT
*
FROM employee
WHERE NOT EXISTS (
SELECT 1
FROM class
WHERE timing = '3-4'
AND class.emp_id = employee.emp_id
)
;
见这只小提琴 (MySQL)
https://stackoverflow.com/questions/24590838
复制相似问题