【发布时间】:2010-11-04 22:42:46
【问题描述】:
我正在寻找对以下查询的改进,感谢任何输入
with cteA as (
select name, count(1) as "A"
from mytable
where y="A"
group by name
),
cteB as (
select name, count(1) as "B"
from mytable
where y="B"
group by name
)
SELECT cteA.name as 'name',
cteA.A as 'count x when A',
isnull(cteB.B as 'count x when B',0)
FROM
cteOne
LEFT OUTER JOIN
cteTwo
on cteA.Name = cteB.Name
order by 1
【问题讨论】:
标签: sql tsql optimization