Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/sql/70.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/django/22.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
MySQL select/where语句_Mysql_Sql - Fatal编程技术网

MySQL select/where语句

MySQL select/where语句,mysql,sql,Mysql,Sql,我有一个链接到mysql数据库的Web应用程序,其中包含以下字段: field 1:trip_id field 2:trip_destination field 3:trip_description field 4:trip_duration 在webapplication中,我有一个基于以下内容的列表框: ListBox value =1: trip duration 1 - 5 days ListBox value =2: trip duration 6 - 10 days Listbox

我有一个链接到mysql数据库的Web应用程序,其中包含以下字段:

field 1:trip_id
field 2:trip_destination
field 3:trip_description
field 4:trip_duration
在webapplication中,我有一个基于以下内容的列表框:

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语句中

SELECT * FROM trip_table WHERE trip_duration BETWEEN start_day-1 AND end_day+1;
然后,您需要将开始日和结束日替换为您的周期,例如开始日=6结束日=10


希望这能有所帮助。

最简单的形式是,从列表框范围的内部控制值(我不是一个PHP程序员来填补空白),但查询可以

select * 
   from TripTable
   where trip_duration >= ?MinimumDays 
     AND trip_duration <= ?MaximumDays
选择*
从TripTable
其中行程持续时间>=?最小天数
跳闸持续时间=1,跳闸持续时间=6,跳闸持续时间=11,跳闸持续时间20,然后为4
结束为TripDurationType
从…起
TripTable

如何像日期一样存储行程持续时间?您想要1个SQL语句还是4个?我想这是另一个糟糕的数据库设计示例,为什么不将每次行程的持续时间1,2,3,4和rest句柄存储为tinyint或enum field trip_duration 1,2,3,4,并使用phpDo向用户列出每次行程是如何基于持续时间的?(即列出的旅行A是11-20天,旅行B是1-5天,旅行C是20天以上???或者,您只是想让列表框中的人选择假期的长短,并显示哪些旅行基于相同的持续时间?
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