0

我以为我有这个,但很明显我没有。从下表中,我试图在顶部显示做出最积极贡献(文章)的用户,然后是那些没有做出贡献的用户。表格很简单,artc_id是文章 ID,artc_status是显示文章是否被批准的状态。0被批准,1不是,然后是写文章的用户。

我试图达到的结果如下:

Total Contributions Positive    Contributing User
4                   4           2
3                   2           1
1                   1           4
3                   0           3

桌子

"id"    "artc_id"   "artc_status"   "artc_user" "artc_country"
"1"     "1"         "0"             "1"         "US"
"2"     "2"         "0"             "1"         "US"
"3"     "3"         "1"             "1"         "US"
"4"     "4"         "0"             "2"         "US"
"5"     "5"         "0"             "2"         "US"
"6"     "6"         "0"             "2"         "US"
"7"     "7"         "0"             "2"         "US"
"8"     "8"         "1"             "3"         "US"
"9"     "9"         "1"             "3"         "US"
"10"    "10"        "1"             "3"         "US"
"11"    "11"        "0"             "4"         "US"

我想出的Sql

select count(artc_status) as stats , artc_user from contributions where artc_status = 0 group by artc_user order by  stats desc;

我没有像上面发布的那样获得结果。你能帮忙吗?这完全超出了我的范围。

4

2 回答 2

1
select 
     count(artc_status) as stats , 
     count(case when artc_status=1 then 1 end) Positive,      
     artc_user[Contributing User] 
from 
    contributions 
group by 
    artc_user 
order by  stats desc;
于 2013-09-18T14:13:30.433 回答
0

我认为您只需要条件聚合即可获得两个摘要列:

select count(*) as TotalContributions, count(artc_status = 0) as PositiveContributions, artc_user
from contributions
group by artc_user
order by PositiveContributions desc;
于 2013-09-18T14:13:09.220 回答