我有這樣的事情: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值時會發生什麼? –