需要 PHP 和 MySQL 方面的帮助ߪ
我有一个歌曲表,有些歌曲是专辑歌曲,有些是单曲...我有一个专辑表...
歌曲表列:Song_ID、Album_ID、Song_Name、Date_Released、Timestamp_Released
, 其他的... 如果Album_ID为[null]
,则表示该歌曲是单个
专辑表,列:Album_ID、Album_Name、Song_IDs、Date_Released
、其他...
注1:有相册表中没有 Timestamp_Released
注 2:Date_Released
只是没有时间的一天,即“2011-06-16”
我目前正在使用此查询来显示一个表格(在我的 html/php 页面中),其中每一行都是一首单曲或一张专辑(专辑中的歌曲全部显示在一行中作为专辑) )
SELECT
IF(Album_ID IS NULL,s.Song_Name,a.Album_Name) as name,
IF(Album_ID IS NULL,s.Date_Released,a.Date_Released) as datereleased,
s.Timestamp_Released
FROM songs s LEFT JOIN albums a ON (s.Album_ID = a.Album_ID)
GROUP BY 1,2
ORDER BY 2 DESC,1
LIMIT 0,10;
上面的查询根据日期对歌曲和专辑列表进行排序,并为专辑提供专辑中最古老歌曲的 Date_Released
和 Timestamp_Released
...
所以我的问题如何为专辑提供最新歌曲的 Date_Released
和 Timestamp_Released
?
谢谢 :)
I have a table of songs, some songs are album song, and some are singles... And I have a table of albums...
Songs table cols: Song_ID, Album_ID, Song_Name, Date_Released, Timestamp_Released
, others...
If the Album_ID is [null]
, it means the song is a single
Albums table cols: Album_ID, Album_Name, Song_IDs, Date_Released
, others...
Note 1: there is no Timestamp_Released
in albums table
Note 2: Date_Released
is only a day with no time i.e. "2011-06-16"
I'm currently using this query to display a table (in my html/php page) that each row is a single or a album (songs that are in an album are displayed all in one row as album)
SELECT
IF(Album_ID IS NULL,s.Song_Name,a.Album_Name) as name,
IF(Album_ID IS NULL,s.Date_Released,a.Date_Released) as datereleased,
s.Timestamp_Released
FROM songs s LEFT JOIN albums a ON (s.Album_ID = a.Album_ID)
GROUP BY 1,2
ORDER BY 2 DESC,1
LIMIT 0,10;
The query above order the list of songs and albums according to date and give the albums the Date_Released
and Timestamp_Released
of the oldest song in the album...
So my question is how to give the album the Date_Released
and Timestamp_Released
of the newest song in it ?
Thank you :)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
将
s.Date_Released, s.Timestamp_Released
写入MAX(s.Date_Released) 作为 Newest_Date_Released,MAX(s.Timestamp_Released) 作为 Newest_Timestamp_Releasd
更新
Instead of
s.Date_Released, s.Timestamp_Released
writeMAX(s.Date_Released) as Newest_Date_Released, MAX(s.Timestamp_Released) as Newest_Timestamp_Releasd
UPDATE