日期:2014-05-17 浏览次数:20464 次
----------------------------
-- Author :DBA_Huangzj(發糞塗牆)
-- Date :2013-10-16 11:28:44
-- Version:
-- Microsoft SQL Server 2012 (SP1) - 11.0.3128.0 (X64)
-- Dec 28 2012 20:23:12
-- Copyright (c) Microsoft Corporation
-- Enterprise Edition (64-bit) on Windows NT 6.2 <X64> (Build 9200: ) (Hypervisor)
--
----------------------------
--> 测试数据:[a]
if object_id('[a]') is not null drop table [a]
go
create table [a]([IRLang] int)
insert [a]
select 0 union all
select 0 union all
select 0 union all
select 0 union all
select 1 union all
select 1 union all
select 1 union all
select 1 union ALL
select 1
--------------开始查询--------------------------
select SUM(CASE WHEN irlang=0 THEN 1 ELSE 0 end) AS 中文数量,SUM(CASE WHEN irlang=1 THEN 1 ELSE 0 END ) AS 英文数量
from [a]
----------------结果----------------------------
/*
中文数量 英文数量
----------- -----------
4 5
*/
select sum(case when irlang = 0 then 1 else 0 end) as 中文数量,
sum(case when irlang = 1 then 1 else 0 end) as 英文数量
from a