phpMyAdmin中INTERSECT的替换

byqmnocz  于 2022-11-09  发布在  PHP
关注(0)|答案(2)|浏览(116)

我尝试在phpMyAdmin上使用一个intersect查询,但是很明显它不支持INTERSECT,至少我很确定它不支持。这是我尝试使用的查询,但是还有什么方法可以把它放在我不使用INTERSECT的地方呢?

SELECT cust_code, cust_fname, cust_lname 
FROM lgcustomer join lginvoice USING (cust_code) WHERE employee_id = 83649
INTERSECT
SELECT cust_code, cust_fname, cust_lname 
FROM lgcustomer join lginvoice USING (cust_code) WHERE employee_id = 83677
ORDER BY cust_lname, cust_fname;
e5nszbig

e5nszbig1#

你说得对,MySQL不支持INTERSECT。

SELECT cust_code, cust_fname, cust_lname 
FROM lgcustomer join lginvoice USING (cust_code) 
WHERE employee_id IN (83649, 83677)
GROUP BY cust_code, cust_fname, cust_lname
HAVING COUNT(DISTINCT employee_id) = 2

更新:MySQL 8.0.31(2022年10月11日发布)支持INTERSECT。请参阅https://lefred.be/content/intersect-and-except-in-mysql-8-0/

9w11ddsr

9w11ddsr2#

请改用联接:

SELECT cust_code, cust_fname, cust_lname 
FROM lgcustomer 
join lginvoice l1 on l1.cust_code = lgcustomer.cust_code AND l1.employee_id = 83649
join lginvoice l2 on l2.cust_code = lgcustomer.cust_code AND l2.employee_id = 83677

相关问题