有6张桌子
tours_atp (_ wta-相同)
games_atp (_ wta-相同)
有了tours_atp + games_atp,一切都可以了,但是我如何才能加入(或在select里面)玩家表中包含玩家名称的接收列,像这样
ID1_G, ID2_G, player1, player2, id_t.....
我尝试选择内部联接
SELECT DISTINCT `ID_T_G` AS `id_t`, `NAME_T` AS `name`, `DATE_G`, `RESULT_G`, `DATE_T`, `COUNTRY_T`, `ID1_G`, `ID2_G`, `ID_R_G`,
(SELECT CONCAT(`NAME`, ' ', `LASTNAME`) AS player1 FROM players_ru_atp WHERE games_atp.ID1_G = players_ru_atp.ID_P) AS `player1`,
(SELECT CONCAT(`NAME`, ' ', `LASTNAME`) AS player2 FROM players_ru_atp WHERE games_atp.ID2_G = players_ru_atp.ID_P) AS `player2`
FROM `games_atp` LEFT JOIN `tours_atp` ON tours_atp.ID_T = games_atp.ID_T_G
WHERE (`DATE_G` BETWEEN '2018-06-29' AND '2018-06-29')
AND (`player1` LIKE '%John Doe%') GROUP BY `ID_T_G`;
但Unknown column 'player1' in 'where clause'
答案 0 :(得分:1)
尝试一下。但是您的GROUP BY
没有道理。
SELECT DISTINCT `ID_T_G` AS `id_t`
, `NAME_T` AS `name`
, `DATE_G`, `RESULT_G`
, `DATE_T`, `COUNTRY_T`
, `ID1_G`, `ID2_G`
, `ID_R_G`
, (SELECT CONCAT(`NAME`, ' ', `LASTNAME`) AS player1 FROM players_ru_atp WHERE games_atp.ID1_G = players_ru_atp.ID_P) AS `player1`
, (SELECT CONCAT(`NAME`, ' ', `LASTNAME`) AS player2 FROM players_ru_atp WHERE games_atp.ID2_G = players_ru_atp.ID_P) AS `player2`
FROM `games_atp`
LEFT JOIN `tours_atp` ON tours_atp.ID_T = games_atp.ID_T_G
WHERE `DATE_G` BETWEEN '2018-06-29' AND '2018-06-29'
AND (SELECT CONCAT(`NAME`, ' ', `LASTNAME`) AS player1 FROM players_ru_atp WHERE games_atp.ID1_G = players_ru_atp.ID_P) LIKE '%John Doe%'
GROUP BY `ID_T_G`;