如果表中不存在IN()条件值,如何将结果设为0

时间:2017-03-30 01:45:35

标签: mysql sql

我的表是:

s_no  user  join_year  knowledge handled_pojects_count
1     john     2017    PHP        5
2     john     2017    SQL        5
3     gokul    2017    JAVA       3
4     gokul    2017    PHP        2
5     hari     2017    ASP        1
6     hari     2017    Azure      9

下面是我的查询

SELECT 
COALESCE(SUM(handled_pojects_count),0) AS count,
knowledge
FROM team_members WHERE
join_year = '2017' AND 
user = 'john' AND 
knowledge IN ('PHP','JAVA');

我需要的结果应该包含以下知识的两个值

    project count
    PHP     5
    JAVA    0

我怎么能到达这个?

2 个答案:

答案 0 :(得分:3)

你能试试吗?

Task taskReturned = Task.WhenAll(taskArray);
try
{
    await taskReturned;
}
catch
{
    throw taskReturned.Exception;
}

答案 1 :(得分:0)

低于一个工作罚款。 谢谢你的帮助!

SELECT 
knowledge,
SUM(CASE WHEN join_year = 2017 AND user = 'john' THEN handled_pojects_count ELSE 0 END) as cnt
FROM team_members WHERE
knowledge IN ('PHP','JAVA')
GROUP BY knowledge