Tag/
共72个网摘 [
1 2 3 ]
下一页 |
my22xo收录,使用标签:SQL语句,时间:2008-3-31 22:23:41 | 相关网摘,我也收藏
Create Table #table1
(
CustomerID int,
CompanyId nvarchar(256)
)
Create Table #table2
(
CustomerID int,
Disabled int
)
insert into #table1
select
12,'YA' union select
13,'YA' union select
14,'YA' union select
15,'YC' union select
16,'YD'
insert into #table2
select
12,0 union select
14,1 union select
15,1
select count(t2.CustomerID) '启用数量',
count(t1.CustomerID) '总数',
(cast((round(cast(((cast((count(t2.CustomerID)) as decimal(38,2))/cast((count(t1.CustomerID)) as decimal(38,2)))*100) as decimal(38,2)),2)) as nvarchar(16)))+'%' as '所占比例',CompanyId
from #table1 t1
left join #table2 t2 on t1.CustomerID=t2.CustomerID
group by CompanyId
http://topic.csdn.net/u/20080331/19/b8a3ff9a-246b-4450-8f04-963102da93d6.html?seed=1455417270
共72个网摘 [
1 2 3 ]
下一页