1

我有这个 SQL 查询,

select * from (select * from .......) as a
where 1 = case when CountOfInnerSelect = 1 Then 1 ELSE ............

是否有可能我可以在外部 SELECT 中获得内部选择的计数?

4

2 回答 2

1

是的 :

select * from (select count(0) as cnt from .......) as a
where 1 = case when a.cnt = 1 Then 1 ELSE ............
于 2012-11-26T09:06:10.967 回答
1

WHERE Clause没有多大意义,因为它在这里像过滤器一样应用。(即;类似于WHERE myCount = 1

SELECT * FROM
(SELECT c1,c2,c3,..,Cn,COUNT(*) AS myCount
 FROM YourTable
 GROUP BY c1,c2,c3,..,Cn
) A
WHERE 1 = CASE myCount WHEN 1 THEN 1 ELSE... END
于 2012-11-26T09:09:45.217 回答