MySQL ORDER BY multiple elements in different where clauses -


I have a question for which I do not know how to call it properly. Maybe I do not use the correct name and therefore I could not find the answer.

But it is the case

  • Buking_ Start (Waimdi)
  • Buking_sttaim (H: A database table to me to come): booking_hotelstart (ymd)
  • booking_hotelstart (ymd)
  • booking_hotelstarttime (Ymd)
  • booking_hotelend (ymd) >
  • booking_hotelendtime (h: i)
  • booking_and (ymd)
  • booking_and time (h: i)
  • booking_enable ( Boole)

    Now I want to do a query that is about it: (What I want to do is to show it A invalid question)

      SELECT `booking_id` to` system_bookings` WHERE ((`booking_start` = '2014 -10-20' order 'booking_stime' ASC) or (` booking_hotelstart `= '2014-10-20' Order 'booking_hotelstarttime' asc) or (` booking_hotel '=' 2014-10-20 'order booking_and time' ASC) or (`booking_and` = '2014-10-20' order booking_and time 'ASC') and `booking_screated` = threshold of truth 0, 100   

    then originally section with one command. But how to do it ?? I have no clue how to find it correctly. So I hope someone can show me some direction, which I should go on. Other than that. I would like to know how it is called. For next searches.

    Thanx in advance!


    Edit:

    According to the request I created some sample data:

      do not create tables `Well system_bookings` (` booking_id` int (6) nOT NULL AUTO_INCREMENT, `booking_start` not on NULL,` booking_starttime` varchar (5) is not NULL, `booking_hotelstart` NULL not on, `booking_hotelstarttime` varchar (5) is not NULL, `booking_hotelend` not on nULL,` booking_hotelendtime` varchar (5) is not nULL, `booking_end` not on nULL,` booking_endtime` varchar (5) is not nULL, `Booking_confirmed` tinyint (1) nULL, pRIMARY KEY ( `Buking_aidi`) ) Engine = InDebbi default charge = latin1 AU TO_INCREMENT = 6; `Putting System_bookings` (` booking_id`, `booking_start`,` booking_starttime`, `booking_hotelstart`,` booking_hotelstarttime`, `booking_hotelend`,` booking_hotelendtime`, `booking_end`,` booking_endtime`, `booking_confirmed`) values ​​(1, '2014-10-09', '21: 19 ',' 2014-10-08 ', '21: 19', '2014-10-23', '08: 00 ',' 2014-10-23 ',' 22: 00 ', 1), (2,' 2014-10-11 ', '16: 00', '2014-10-27', '12: 15 ',' 2014-10-28 ', '17: 45 ',' 2014-10-28 ', '17: 45', 1), (3, '2014-10-10', '20: 30 ',' 2014-10-10 ', '20 : 30 ',' 2014-10-11 ', '08: 00', '2014-10-20', '14: 00 ', 1), (4,' 2014-10-12 ', '20: 00 ',' 2014-10-12 ', '20: 00', '2014-10-13', '05: 00 ',' 2014-10-29 ', '22: 00', 0), (5, '2014-10-22', '15: 00 ',' 2014-10-22 ', '20: 30', '2014-10-23', '04: 15 ',' 2014-10-31 ', '12: 00 ', 1);    

    You can have several conditions in the order section. So, formally, you want it:

      SELECT `booking_id` Se` system_bookings` where 'Buking_sukunit` = right (` Buking_ start` =' 2014-10-20 'OR' Booking_hotelstart` = '2014-10-20' or `booking_hotel '=' 2014-10-20 'or` booking_and` =' 2014-10-20 ') Order (in case when `booking_start` =' 2014-10-20 And 'then `Buking_sttaim` WHEN` Buking_hotlstart` =' 2014-10-20 'and' Buking_hotlstarttaim` when` Buking_hotlend` = '2014-10-20' then 'Buking_andtaim` WHEN` Buking_and` =' 2014-10-20 ' 'Booking_and time'END) LIMIT 0, 100; However, this is a bit unresponsive, because you are comparing a value for a constant, and then sorting that value. I suspect that you want to give priority to  where  rules and actually want to do something else like this:  
      by order (case when `booking_start` = '2014-10-20' then at 1 a.m. when `booking_hotelstart` = '2014-10-20' then 2 WHEN` booking_hotel '=' 2014-10-20 'then 3 WHEN` booking_and` =' 2014-10-20 ' THEN 4 END)    

  • Comments

    Popular posts from this blog

    php - PDO bindParam() fatal error -

    logging - How can I log both the Request.InputStream and Response.OutputStream traffic in my ASP.NET MVC3 Application for specific Actions? -

    java - Why my included JSP file won't get processed correctly? -