您好我有一个查询,从我的房屋表中选择所有按街道地址分组的房屋。它统计了该街道上有多少人,但也计算了另一个游说桌中引用该街道的数量。
我的查询在MYSQL中工作但是当我在我的iOS应用程序中使用SQlite尝试它时它不起作用。我不知道两者之间是否有一些语法差异?
SELECT haddress AS hd, COUNT( * ) ,
(
SELECT COUNT( * )
FROM canvass, house
WHERE canvass.hid = house.hid
AND house.haddress = hd
)
FROM house
GROUP BY haddress
答案 0 :(得分:5)
似乎您无法在SQLite的内部查询中引用列别名,因此您必须稍微更改内部查询以使用house
的别名,以便引用外部house.haddress
。更改后的查询应该适用于SQLite和MySQL;
SELECT haddress AS hd, COUNT( * ),
(
SELECT COUNT( * )
FROM canvass, house house2
WHERE canvass.hid = house2.hid
AND house2.haddress = house.haddress
)
FROM house
GROUP BY haddress