1.统计任务提交情况
2.A(id,name)人员表,B(bid,aid, mission)任务提交记录表,aid 对应id,mission为字符串字段,一个人可提交多次任务,示例数据
id name
1 张三
2 李四
3 王五
bid aid mission
1 1 xxxxx
2 1 yyyyy
3 2 zzzz
sql: select A.name,if(mission<>null,1,0) as mnum from A leftjion B on B.aid= A.id orderby id
得到是
name mnum
张三 0
张三 0
李四 0
王五 0
本来最终想得到如下效果,那么SQL怎么写
name 任务次数
张三 2
李四 1
王五 0
This sentence was tested successfully
SELECT NULL IS NULL, NULL IS NOT NULL, NULL = NULL, NULL <> NULL
You will know why your if does not work if you run them separately.
According to SQL specifications, the result of all operations with NULL is NULL, so special methods need to be used to judge NULL
1. IFNULL function
2. Mission<>null is changed to mession is not null