简体   繁体   中英

How to write sql query for show one data record from multi data record (LIKE or IN)?

cite_name

  1. London
  2. Karachi
  3. New York ...

city_type

  1. 1,2,3
  2. 2,3

  3. 3,4

how to write query to find the all cities having city_type like 3?

SELECT* FROM [your_table] WHERE city_type LIKE '%3%'

Use FIND_IN_SET

select * from [your_table] where FIND_IN_SET(city_type,'3') > 0 

Note : Storing more than one value in single column separated by comma is bad way to store information. Consider changing your table structure. Have a separate table for CITY_TYPE and map it with your table for each CITY in separate rows

只需在开始和结束时使用带有通配符的LIKE ,就像这样

SELECT * FROM TABLE_NAME WHERE city_type LIKE '%3%';

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