34,587
社区成员
发帖
与我相关
我的任务
分享
create table tblSalse(
id int not null,
time datetime not null,
salse int not null,
succ_ind tinyint not null
)
select t1.id,t1.sums,t2.succCount*100.0/t1.totalCount as succ_rate
from
(select id,sum(salse) as sums,count(succ_ind) as totalCount from tblSalse
where time between starttime and endtime) as t1
left join
(select id,count(succ_ind) as succCount from tblSalse where time between starttime and endtime) as t2
on t1.id=t2.id
create table tb(id int,name varchar(10))
insert into tb select 1,'a'
insert into tb select 2,'b'
insert into tb select 3,'c'
insert into tb select 4,'d'
select sum(case when name='a' then 1 when name='b' then 2 when name='c' then 2 end) as '和'
from tb
select t1.id,t1.sums,t2.succCount*100.0/t1.totalCount as succ_rate
from
(select id,sum(salse) as sums,count(succ_ind) as totalCount from tblSalse
where time between starttime and endtime) as t1
left join
(select id,count(succ_ind) as succCount from tblSalse where succ_ind=1 and time between starttime and endtime) as t2
on t1.id=t2.id