Home > Database > Mysql Tutorial > Mysql字符串函数FIND_IN_SET()的两点用法_MySQL

Mysql字符串函数FIND_IN_SET()的两点用法_MySQL

WBOY
Release: 2016-06-01 13:02:05
Original
1231 people have browsed it

概要:该可以查询用逗号分割的字段,以及对结果进行强制排序

首先看一张表:

colid vyear area cast
,31,32,21,12 2014 1 15
,32,33,34,35,21, 2014 2 16
,33,34,36,39,40 2011 3 17

表中的colid字段的值是以逗号分割,

当我们需要查询这张表中,colid含有32的行,

那么可以用FIND_IN_SET()

SQL如下: 

SELECT * FROM table WHERE FIND_IN_SET('32', colid);
Copy after login
强制排序的话可以这么写:
SELECT
	*
FROM
	table
WHERE
	area IN(2,1,3) 
ORDER BY 
        find_in_set(area,'2,1,3');
Copy after login
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template