我正在尝试检查内部select语句中的总计数(*)
SELECT * FROM CAR WHERE 4 <= ( SELECT COUNT(*) FROM CAR_DRIVER WHERE CAR.C_CARKEY = CAR_DRIVER.CD_CARKEY );
我试过了 select count as total 但是它不起作用,因为变量total只在内部select语句中有效。
select count as total
i7uq4tfw1#
使用 join 因此您可以获取值:
join
SELECT c.*, cd.cnt FROM CAR c JOIN (SELECT cd.CD_CARKEY, COUNT(*) as cnt FROM CAR_DRIVER cd GROUP BY cd.CD_CARKEY ) cd ON c.C_CARKEY = cd.CD_CARKEY WHERE cnt >= 4;
1条答案
按热度按时间i7uq4tfw1#
使用
join
因此您可以获取值: