22,209
社区成员
发帖
与我相关
我的任务
分享
,count(distinct case when Cha_IsPrivilege = 1 then stu_id end) as youtims
select * from tb_charge sc
inner join tb_Curriculum_Schedule cc on sc.curr_id=cc.curr_id
select substring(curr_beginclass,1,4)+' '+Curr_Term_Name as xueqi,--时间
count(distinct stu_id) as allPeople,--人数
count(stu_id) as stutimes,--人次
count(case when Cha_IsPrivilege = 1 then 1 end) as youPeople--优惠人次
,count(distinct stu_id case when Cha_IsPrivilege = 1 then 1 end) as youtims --优惠人数? 不会了因为 这里case 和 distinct 操作的不是同一列
from tb_charge sc
inner join tb_Curriculum_Schedule cc on sc.curr_id=cc.curr_id
group by substring(curr_beginclass,1,4),Curr_Term_Name
select substring(curr_beginclass,1,4)+' '+Curr_Term_Name as xueqi,--时间
count(distinct stu_id) as allPeople,--人数
count(stu_id) as stutimes,--人次
count(case when Cha_IsPrivilege = 1 then 1 end) as youPeople--优惠人次
,count(case when Cha_IsPrivilege = 1 then 1 end) as youtims --优惠人数? 不会了
from tb_charge sc
inner join tb_Curriculum_Schedule cc on sc.curr_id=cc.curr_id
group by substring(curr_beginclass,1,4),Curr_Term_Name
DECLARE @T TABLE(A INT)
INSERT INTO @T
SELECT 1 UNION ALL
SELECT 1 UNION ALL
SELECT 2 UNION ALL
SELECT 2 UNION ALL
SELECT 3 UNION ALL
SELECT 4
SELECT COUNT(DISTINCT CASE A WHEN 3 THEN 1 ELSE A END )
FROM @T
IF OBJECT_ID('tb') IS NOT NULL
DROP TABLE tb
GO
CREATE TABLE tb(id int ,list_id int,is_type int )
go
insert tb SELECT 1,2,1
UNION ALL SELECT 2,1,0
UNION ALL SELECT 3,2,1
UNION ALL SELECT 4,4,1
UNION ALL SELECT 5,1,1
go
select COUNT(distinct case list_id when 2 then 1 else list_id end) from tb
/*
-----------
2
(1 行受影响)
*/
可以加,如这样.