2015-11-03 83 views
1

排除NULL值我有这种情况在表SQL组由分组

client staff code time1 time2 
------------------------ 
c1  null code1 
c2  null code1 
null  s1  code1 
null  s2  code1 

试图通过人员和代码行分组:

SELECT GROUP_CONCAT(client),staff,code from table GROUP BY staff,code 

我得到明显:

client staff code ... time1 time2 
------------------------ 
c1,c2 null code1 
null  s1  code1 <- 
null  s2  code1 <- 

对于该功能的目的要求,我需要的条目“重点”的工作人员,所以我也可以得到相对时间1和时间2。 问题是,上面箭头指示的行没有任何客户端ID,因此没有机会检索其数据。 客户信息进入staff = null行。

我怎样才能做到这样呢?

client staff code ... time1 time2 
------------------------ 
c1,c2 s1  code1 <- 
c1,c2 s2  code1 <- 

感谢

+0

你想要的代码1为每个员工的所有客户端的时间?我想在time1字段中使用数据所需的一个示例可以更容易地回答您的问题。 – idstam

+0

这个问题的目的不是主要问题。 我需要有关于每行员工的c1,c2。这是主要问题。 –

回答

0

where条款group像在此之前: -

SELECT GROUP_CONCAT(client),staff,code from table 
where client IS NOT NULL AND staff IS NOT NULL 
GROUP BY staff,code 
+1

与此我不会得到任何行,因为没有任何行与客户端和工作人员不是null在同一迭代。 –