次のようなクエリがあります..
SELECT id_b FROM id_table
WHERE id_a = ?
AND (
SELECT COUNT(*) AS rowCount FROM other_table
WHERE id = id_b
) > 0;
値rowCountを取得するにはどうすればよいですか?
編集: これは MYSQL DB です
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
あなたは試すことができます:
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で機能します