如何使用mysql设置子查询结果的默认值
SELECT
p.`id`, p.`name`, p.`class_name`, cpd.`status_team`,
cpd.`home`, cpd.`guest`, cpd.`mvp`, cpd.`oscar`,
cpd.`wam`, cpd.`status`, cpd.`added_date`,
(SELECT result FROM result_cards WHERE `id` = cpd.`result`) AS DEFAULT(`result`)
FROM `cron_players_data` cpd
INNER JOIN `players` p ON cpd.`player_id` = p.id
WHERE cpd.`added_date` = '2012-03-29' AND cpd.team_id = '15'
当我删除此默认值()时,查询将正常执行。实际上,我希望默认的结果值是0,或者绝对感谢帮助
最佳答案
您应该将子查询移动到联接。但我无法理解您试图用default()做什么。你需要解释你想要达到的目标。
SELECT
p.`id`, p.`name`, p.`class_name`, cpd.`status_team`,
cpd.`home`, cpd.`guest`, cpd.`mvp`, cpd.`oscar`,
cpd.`wam`, cpd.`status`, cpd.`added_date`,
IFNULL(rc.`result`, 0) AS `result`
FROM `cron_players_data` cpd
INNER JOIN `players` p
ON cpd.`player_id` = p.id
LEFT JOIN result_cards rc
ON cpd.`result` = rc.id
WHERE cpd.`added_date` = '2012-03-29'
AND cpd.team_id = '15'
关于mysql - 如何使用mysql在SubQuery结果中设置默认值,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/9928780/