是否有一种方法可以改变我查看查询结果的方式?
我举个例子。我有一张表,上面有市场的id,然后是市场的名称,还有体育ID。我希望将体育id显示为体育名称。
SELECT id, name, sport_id FROM markets where sport_id = 2;我在想:
SELECT * FROM markets where sport_id = 2 as 'Football'; 但那不管用。我不想像更新那样修改结果,我只希望结果以足球的形式显示,而不是sport_id 2。
这个是可能的吗?
发布于 2015-05-14 16:09:04
如果您只有一个表,并且喜欢给Alias,那么就转到查询1。
SELECT id, name, sport_id AS 'sport name' FROM markets where sport_id = 2;或
如果您有两个不同的表,那么您需要与其他表连接,如下所示
SELECT m.id, m.name, t.sport_name
FROM markets m
JOIN other_Table t ON m.sport_id = t.sport_Id
where m.sport_id = 2;我希望这对解决你的问题有帮助。
发布于 2015-05-14 15:37:51
可以使用JOIN对sports表执行此操作,如下所示:
SELECT m.id, m.name, s.sport_name
FROM markets m
JOIN sports s
ON m.sport_id = s.sport_Id
where m.sport_id = 2;https://stackoverflow.com/questions/30241355
复制相似问题