2011-01-10 134 views
0

我已经连接到MySQL数据库具有以下字段的web应用:MySQL的选择/ where语句

field 1:trip_id 
field 2:trip_destination 
field 3:trip_description 
field 4:trip_duration 

在web应用我有基于以下列表框:

ListBox value =1: trip duration 1 - 5 days 
ListBox value =2: trip duration 6 - 10 days 
Listbox value =3: trip duration 11 -20 days 
ListBox value =4: trip duration over 20 days 

怎么办我把这个在sql select语句中?

+0

你如何存储TRIP_DURATION像一个约会我会申请一个CASE ?你想要1个SQL语句还是4个? – Navi 2011-01-10 11:30:38

回答

0
SELECT * FROM trip_table WHERE trip_duration BETWEEN start_day-1 AND end_day+1; 

然后,您需要将start_day和end_day替换为您的句点。 start_day = 6 end_day = 10。

希望这会有所帮助。

0

以其最简单的形式,从你内部控制的列表框范围内(并且我不是一个PHP程序员来填空),但是查询可能是这样。

select * 
    from TripTable 
    where trip_duration >= ?MinimumDays 
    AND trip_duration <= ?MaximumDays 

如果你试图让所有行程,并与他们1-4分级预盖章,当

select *, 
     case 
     when trip_duration >= 1 and trip_duration <=5 then 1 
     when trip_duration >= 6 and trip_duration <=10 then 2 
     when trip_duration >= 11 and trip_duration <=20 then 3 
     when trip_duration > 20 then 4 
     end as TripDurationType 
    from 
     TripTable