我有一个查询,看起来像..
SELECT id_b FROM id_table
WHERE id_a = ?
AND (
SELECT COUNT(*) AS rowCount FROM other_table
WHERE id = id_b
) > 0;如何检索值rowCount?
编辑:这是一个MYSQL数据库
发布于 2012-06-14 12:58:57
Select A..., Z.RowCount
From id_table As A
Cross Join (
Select Count(*) As RowCount
From other_table
Where id_b = ?
) As Z
Where A.id_a = ?
And Z.RowCount > 0编辑
考虑到您的编辑,我猜您正在尝试实现类似于:
Select A..., Z.RowCount
From id_table As A
Join (
Select id_b, Count(*) As RowCount
From other_table
Group By id_b
) As Z
On Z.id_b = A.id_b
Where A.id_a = ?
And Z.Cnt > 0发布于 2012-06-14 12:43:04
您可以尝试:
SELECT (
SELECT COUNT(*) AS rowCount FROM other_table
WHERE id_b = ?
) AS rowCount, id_b FROM id_table
WHERE id_a = ?
AND (
SELECT COUNT(*) AS rowCount FROM other_table
WHERE id_b = ?
) > 0;这在SQL Server中是可行的
https://stackoverflow.com/questions/11026744
复制相似问题