优化select语句
select COUNT(* )from
(
select resourceURL,resourceAnchor,categoryName from tResources,tCategory where categoryID like '0[^0]%' and resourceAnchor like '%'+categoryName+'%'
) as d
select COUNT(* )from
(
select resourceURL,resourceAnchor,categoryName from tResources,tCategory where categoryID like 'G%' and resourceAnchor like '%'+categoryName+'%'
) as c
select COUNT(* )from
(
select resourceURL,resourceAnchor,categoryName from tResources,tCategory where categoryID like '00%' and resourceAnchor like '%'+categoryName+'%'
) as c
select COUNT(* )from
(
select resourceURL,resourceAnchor,categoryName from tResources,tCategory where categoryID like 'R%' and resourceAnchor like '%'+categoryName+'%'
) as c
怎么将这四个查询在一个语句中进行,像我这样写,速度太慢了,求大神
------解决方案--------------------4个写在一个结果中?
select
sum(case when a.categoryID like '0[^0]%' and b.resourceAnchor like '%'+categoryName+'%' then 1 else 0 end) ,
sum(case when a. categoryID like 'G%' and b.resourceAnchor like '%'+categoryName+'%' then 1 else 0 end)
.....
from
tResources as a inner join tCategory as b on a. categoryID =b. categoryID