English 中文(简体)
帮助KQ
原标题:Help with a SQL query
  • 时间:2009-08-27 08:50:33
  •  标签:

我不得不做一个问询,根据意见数,把十大册上调。 意见的数量实际上是具体名称中每一名歌曲的意见的总和。

我的表格是:

albums:
- album_id
- album_name
- album_owner

songs:
- song_id
- song_name
- song_album
- song_owner
- song_views

你们能够帮助我摆脱这种局面?

最佳回答
select sum(song_views) as  song_sum ,album_name 
from albums a 
inner join 
songs s 
on a.album_id = s.song_album 
group by album_name 
order by song_sum DESC 
limit 0,10;

如果歌曲指背书......

问题回答

为此:

SELECT  TOP 10 a.album_id, a.album_name, a.album_owner, SUM(s.song_views)
FROM    albums a
        INNER JOIN
                songs s
                ON a.album_id = s.song_album
GROUP BY a.album_id, a.album_name, a.album_owner
ORDER BY SUM(s.song_views) DESC

类似:

select top 10 song_album
from songs
group by song_album
order by sum(song_views) desc

我不能这样说,但应该遵循这样的方针。

select album_name, sum(song_views) as views from albums join songs on songs.album_id = songs.song_album group by album_id order by views desc limit 10 

SELECT TOP 10 song_album FROM songs GROUP BY song_album ORDER BY sum(song_views) desc





相关问题
热门标签