SQLAlchemy子查询不工作

2024-05-16 18:43:47 发布

您现在位置:Python中文网/ 问答频道 /正文

我试图完成以下查询:

SELECT *, (SELECT COUNT(*) FROM cars WHERE status = 1) total
FROM cars
WHERE status = 1
LIMIT 5;

这是我的python代码:

^{pr2}$

但它生成的查询完全不同:

SELECT cars.id AS cars_id, cars.status AS cars_status, anon_1.total AS anon_1_total 
FROM cars, (SELECT count('*') AS total 
FROM cars 
WHERE cars.status = 1) AS anon_1 
WHERE cars.status = 1 
LIMIT 5

是否可以强制子查询的WHERE子句作为子查询的一部分?在


Tags: 代码fromidasstatuscountwherecars