【发布时间】:2013-08-04 02:02:00
【问题描述】:
我尝试了几件事,但找不到过滤此代码以一次只显示一年的方法。我添加了 WHERE 语句,以及如下语句:
DATE_FORMAT(show_date, '%Y') = 2013
但似乎没有任何效果,它只是错误代码并且什么也没显示......
$mostplayed = mysqli_query($con,"SELECT tbl_shows.song_id, tbl_songs.song_name,
count(tbl_shows.song_id) as cnt, MID(song_name,1,35) as short_name, tbl_shows.show_date
FROM tbl_shows LEFT JOIN tbl_songs
ON tbl_shows.song_id = tbl_songs.song_id
GROUP by tbl_shows.song_id
ORDER by count(tbl_shows.song_id) desc
LIMIT 5");
echo "<table style='float: left; height:150px; margin-right:30px;'>";
echo "<tr style='background-color:transparent;'>";
echo "<td>";
echo "<h4>Most Played Songs:</h4>";
while($row = mysqli_fetch_array($mostplayed))
{
echo $row['short_name'];
echo " (" . $row['cnt'].")</br>";
}
echo "</td></tr></table>";
代码本身返回歌曲,后跟括号中的计数。谁能指出我如何一次只显示一年,根据 song_date 年份过滤掉数据?谢谢你。任何帮助,将不胜感激。
上面的代码有效,但获取了两年的所有数据...... 下面的代码不返回任何内容
SELECT tbl_shows.song_id, tbl_shows.show_date, tbl_songs.song_name,
count(tbl_shows.song_id) as cnt, MID(song_name,1,35) as short_name
FROM tbl_shows LEFT JOIN tbl_songs WHERE show_date BETWEEN '2013-01-01' AND '2013-12-31'
ON tbl_shows.song_id = tbl_songs.song_id
GROUP by tbl_shows.song_id
ORDER by count(tbl_shows.song_id) desc
LIMIT 5
我会尽快收集一些数据点...
【问题讨论】: