鍍金池/ 問答/PHP  數(shù)據(jù)庫/ mysql 時(shí)間段比較

mysql 時(shí)間段比較

mysql 表字段
分類表,showtime:字段是時(shí)間段表的ID

id  showtime   detail


時(shí)間段表

id start_time end_time 

現(xiàn)在要查詢?cè)诋?dāng)前時(shí)間段內(nèi)的所有分類

實(shí)在是想不出來可以按照這個(gè)條件直接查出的語句
現(xiàn)在處理方式是查詢出來之后在遍歷比較!

可不可以直接查詢?這種語句有嗎?

回答
編輯回答
你的瞳

select * from a left join b on a.showtime=b.id

2017年1月9日 21:51
編輯回答
尛憇藌

兩表join

2017年6月10日 00:13
編輯回答
單眼皮

分類表:tb_category 時(shí)間表 tb_time
參數(shù):當(dāng)前時(shí)間段的id

select tc.* from tb_time tt
left join tb_category tc on tt.id = tc.id 
where tc.start_time >=tt.showtime and tt.showtime<=tc.end_time and tt.id = ?
2017年3月30日 11:51