gpt4 book ai didi

mysql - 如何在sql中合并2列并排序

转载 作者:行者123 更新时间:2023-11-29 22:43:50 25 4
gpt4 key购买 nike

我正在尝试对 2 个以 channel 和 View 作为列的表进行排序。我需要将 channel 和 View 合并到 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 和 COASCE,但没有成功。

最佳答案

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

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

关于mysql - 如何在sql中合并2列并排序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29215873/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com