回答此问题可获得 20 贡献值,回答如果被采纳可获得 50 分。
<p>我有一个学校申请表,看起来像这样。。。你知道吗</p>
<pre><code>create table todel (user_id int, SchemesApplicable1 int, SchemesApplicable2 int,
SchemesApplicable3 int, SchemesApplicable4 int);
insert into todel values (1, 1, 0, 1, 0);
insert into todel values (2, 0, 0, 0, 0);
insert into todel values (3, 1, 0, 1, 0);
insert into todel values (4, 1, 0, 0, 0);
insert into todel values (5, 1, 0, 1, 1);
SELECT Count(User_Id) as No_Off_Application ,
sum(if(SchemesApplicable1 = 1, 1, 0)) as first,
sum(if(SchemesApplicable2 = 1, 1, 0)) as second,
sum(if(SchemesApplicable3 = 1, 1, 0)) as third,
sum(if(SchemesApplicable4 = 1, 1, 0)) as forth
FROM todel
</code></pre>
<p>上面的查询将返回如下报告。。。你知道吗</p>
<pre><code>No_Off_Application first second third forth
5 4 0 3 1
</code></pre>
<p>我想再加上一个栏,列出申请多个计划的申请人。
预期计数为3(用户id为1、3和5)
如何为此编写查询?你知道吗</p>