如何在sql和sort中组合2列

时间:2015-03-23 16:54:06

标签: mysql sql join

我试图将2个包含通道和视图的表排序为列。我需要将通道和视图组合成2个新列并显示它们。

我试过的代码:

    SELECT IFNULL( youtube_gaming_channels_most_viewed.channel,  '' ) + 
    IFNULL( most_popular_twitch_streamers.Channel,  '' ) AS channel, 
    IFNULL( youtube_gaming_channels_most_viewed.views,  '' ) + 
    IFNULL( most_popular_twitch_streamers.Views,  '' ) AS views
    FROM youtube_gaming_channels_most_viewed
    INNER JOIN most_popular_twitch_streamers
    ORDER BY  `views` DESC 

我也尝试过CONCAT AND COASCE但没有成功。

1 个答案:

答案 0 :(得分:0)

如果查询正常但未排序,您可以使用查询作为语句

select channel,views from 
(
 SELECT IFNULL( youtube_gaming_channels_most_viewed.channel,  '' ) + 
    IFNULL( most_popular_twitch_streamers.Channel,  '' ) AS channel, 
    IFNULL( youtube_gaming_channels_most_viewed.views,  '' ) + 
    IFNULL( most_popular_twitch_streamers.Views,  '' ) AS views
    FROM youtube_gaming_channels_most_viewed
    INNER JOIN most_popular_twitch_streamer
    ) v order by views DESC