简体   繁体   English

MySQL select / where语句

[英]MySQL select/where statement

I have a webapplication linked to a mysql database with the following fields: 我有一个使用以下字段链接到mysql数据库的Web应用程序:

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

In the webapplication I have a listbox based on the following: 在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

How do I put this in the sql select statement? 如何将其放在sql select语句中?

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

You would then need to replace start_day and end_day with your periods eg start_day = 6 end_day=10. 然后,您需要用句点替换start_day和end_day,例如start_day = 6 end_day = 10。

Hope this helps. 希望这可以帮助。

in its simplest form, from your internally controlled values of the listbox ranges (and I'm not a PHP programmer to fill in the blanks), but a query could be. 以最简单的形式,从列表框范围的内部控制值中选择(我不是PHP程序员来填补空白),但可以进行查询。

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

If you are trying to get all trips, and have them pre-stamped with a 1-4 classification, I would apply a CASE WHEN 如果您尝试获得所有旅行,并使用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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM