你的表应该这样建立
table1(banci,riqi,neirong) 班次banci int 日期riqi date 
8-16点的banci为1,16-24点的banci为2,24-8点的banci为3
然后你可以写查询
select * from table1 where banci=(case banci when 1 then 3 when 2 then 1 when 3 then 2 end) and riqi=(case banci when 1 then riqi when 2 then riqi when 3 then riqi-1)