Re: [SQL ] 請教這個問題如何下SQL呢?

看板Database作者 (無所事事)時間18年前 (2006/06/25 16:18), 編輯推噓0(000)
留言0則, 0人參與, 最新討論串11/13 (看更多)
※ 引述《ylk (YLK)》之銘言: : ※ 引述《weisor (無所事事)》之銘言: : : 只取一筆 : : select * from T : : order by case when (used > 0) then 1 else 0 end desc, time asc : : limit 1 : : 噁心的寫法 : : select * from T : : join ( : : select case when used > 0 then 1 else 0 end as u, min(time)as t from T : : group by case when used > 0 then 1 else 0 end) x : : on x.u = case when used > 0 then 1 else 0 end and x.t = T.time : : where (exists(select * from T where used > 0) and used > 0) : : or (not exists(select * from T where used > 0) and used = 0) : 謝謝您的指導。 : 想請問您,您的環境是? case 這個欄位代表的意思是? case statement mysql, postgres, db2, mssql 都有支援 請參考 http://msdn2.microsoft.com/zh-tw/library/ms181765.aspx http://www.postgresql.org/docs/8.1/interactive/functions-conditional.html http://publib.boulder.ibm.com/infocenter/db2luw/v8/ topic/com.ibm.db2.udb.doc/admin/r0005646.htm http://dev.mysql.com/doc/refman/5.1/en/case-statement.html -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 59.104.29.35
文章代碼(AID): #14daRezy (Database)
討論串 (同標題文章)
本文引述了以下文章的的內容:
以下文章回應了本文
完整討論串 (本文為第 11 之 13 篇):
文章代碼(AID): #14daRezy (Database)