想别的办法吧!靠一个SQL语句可能不行!要不用储存过程,要不就PHP

解决方案 »

  1.   

    請問helloyou0(你好!) 具體應該如何實現,我找篇幫助文檔都沒頭緒以下是我的具體情況
    表結構
    create table SongTopList
    (
     TopId  SERIAL PRIMARY KEY,--自增量ID
     TopSelectGrade varchar(10) not null,          --歌曲所屬年級
     TopSelectTerm varchar(10) not null,          --歌曲所屬學期
     TopSelectSongId          varchar(10) not null,          --歌曲編號
     TopData      Date default(CURRENT_DATE)     --記錄時間(最近瀏覽日期),默認當前時間
    )首先要求的是列出當前日期本周內點擊最多的五條記錄;SQL如下$SongList_rs = "select TopSelectGrade,TopSelectTerm,TopSelectSongId,count(TopSelectSongId) as TopSongIdcount from SongTopList where TopData between current_date-EXTRACT(DOW FROM now())::integer and current_date+6-EXTRACT(DOW FROM now())::integer group by TopSelectSongId,TopSelectGrade,TopSelectTerm order by TopSongIdcount desc LIMIT 5";但現在有一種情況出現就是當到下周日那天時,如果沒有人點擊過歌曲或者點擊不夠五首的話。那麼點歌排行榜就會空了或者顯示不夠五條。現想解決是如果當前周數據不夠的話,優先將上周數據拿了來放在入面。請問應該如何結合兩組數據的結果集啊?取回上周數據需要考慮的是不能跟本周的數據重復,謝謝!