简体   繁体   中英

How to check whether a value exists among a set of values in a record in mysql

I am using MySQL in such a way that the user enters a date and flights appear on that day.I was too lazy to put many dates so what I did was made certain flights run on certain days.

The table planes contains many columns out of which dtd(column containing many days of type varchar(50)) .

One record(in dtd) is Monday, Tuesday The user enters the date 2018-12-03 which is a Monday.

My problem is how do I extract only the record which has Monday?(like the monday,Tuesday one)??

I tried select.....where instr(day(2018-12-03),dtd)<>0 but I realised that instr gives 0 in 2 cases 1. the character(s) is not present in the record or 2.occurence is at the beginning.

Like instr(h,hello) and instr(a,hello) gives 0.

Please help

I suggest that you use the LIKE operator.
For more info about it please check this link: SQL Like Operator
To solve your problem, you can try the following:

SELECT ...
  WHERE dtd LIKE CONCAT('%', day(2018-12-03), '%');

In this case, you will get all the rows of the table, where the value of the field dtd contains the value of day(2018-12-03).
Hope this helps!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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