select uname, count (cid) from nowday group by uname order by count (cid) desc
select uname, count (cid) from nowday the where the status=2 group by uname order by count (cid) desc
Which means to query the user name, operating capacity, invalid operation quantity (status=2)
If you can, can on the basis of the additional query an invalid operation rate? (invalid operation measure/operation) requires the result is percentage said, keep two decimal places
CodePudding user response:
The select s1 uname, s1 youxiao, s2. Wuxiao from (select uname, count (cid) youxiao from nowday group by uname) s1Left the join
(select uname, count (cid) wuxiao from nowday the where the status=2 group by uname) s2
On s1. The uname=s2. The uname
If I write is
CodePudding user response:
Two statements from the filter, the returned result set to meet the conditions are not consistent, so I can't directly to merge, but can consider to secondary consolidation of the result set,CodePudding user response:
Select the uname, count (cid) from nowday group by uname order by count (cid) descThe union
Select the uname, count (cid) from nowday the where the status=2 group by uname order by count (cid) desc
CodePudding user response:
Can use case, the when, but more troublesomeSelect the uname, count (cid1) as cid1, sum (cid2) as cid2 from
(select uname, 1 as cid1, case when status=2 then one else 0 end as cid2 from nowday) as t group by uname, order by cid1
But merge to ordered at the same time satisfy the two fields