我有这样的事情:SQL从其他列选择第一列随机值的所有不同的行
id email email2 id_2
------------------------------------------
1 [email protected] [email protected] 11
1 [email protected] [email protected] 11
1 [email protected] - 11
1 [email protected] - 11
2 [email protected] [email protected] 22
2 [email protected] [email protected] 44
3 [email protected] - 33
3 [email protected] - 33
4 [email protected] [email protected] 55
,所以我需要选择不同的ID的所有值,如果EMAIL2不是空的,我应该选择一个没有空电子邮件2,但如果只有空的电子邮件2,请选择一个。例如:
id email email2 id_2
------------------------------------------
1 [email protected] [email protected] 11
2 [email protected] [email protected] 22
3 [email protected] - 33
4 [email protected] [email protected] 55
没有更多的条件,所以我不知道该怎么做。通常我使用partiotion或group by ..请帮助我。
当用户有多个email2值时会发生什么? –