2015-05-14 24 views
-1

我正在編寫通知警報功能。我有一個表Notification有一個字段ViewedViewed的值是TINYINT。當用戶查看通知時,它被翻轉到1。然後根據Viewed我顯示已準備好提醒的通知。現在如果沒有新的通知,我想顯示最近查看的通知。我使用的查詢是爲查看的通知撰寫mysql查詢

$query="select * from notification where NotifierId=? and Viewed=0 order by 
NotificationDate DESC "; 

現在我想做的是在僞語言是這樣的

Select Fields from notification where NotifierId=someid and Viewed=0 Incase 
there are new notifications but retreive the old as well Viewed=1 if the new 
notifications are less than 10 ordered by date 

請讓我知道如果有什麼辦法做到這一點。由於

+0

上面目前是功能性...我想要的新的是我不能構成的東西。我無法控制在sql中輸入true和false。 – whatever

+1

Have.you.tried.to.write.the.query?如果沒有任何表格配置,數據或期望的輸出,我們只會猜測你在這裏做什麼。也許設置一個我們可以操縱的SQL小提琴。 –

回答

0

我想你可能會感興趣的是這樣的:

select 
    * 
from 
    notification 
where 
    NotifierId=? and 
    Viewed in (0, IF((select count(*) from notification where Viewed = 0)<10,1,0)) 
order by 
    Viewed asc, 
    NotificationDate desc 

這將導致非看通知全部在上面按日期降序排序,然後在觀看通知將通過日期倒序排列顯示。

我希望我能夠完全理解你的問題,但如果沒有,請讓我知道。

+0

如果沒有查看,'Viewed'字段很重要。或者說是'假' – whatever

+0

通知需要在上面而不是在下面。 – whatever

+0

@whatever是的,''asc''應該這樣做。它不適合你嗎? – MonkeyZeus