IN 查询

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了IN 查询相关的知识,希望对你有一定的参考价值。

IN 查询 :SELECT  字段名1, 字段名2, ...... , 字段名n  FROM  表名  WHERE  查询条件  IN  (范围) ;

mysql> SELECT s_id, f_name, f_price FROM fruits WHERE s_id IN (101,102);
+------+------------+---------+
| s_id | f_name     | f_price |    # 查询s_id为101和102的记录
+------+------------+---------+
|  101 | apple      |    5.20 |
|  101 | blackberry |   10.20 |
|  102 | orange     |   11.20 |
|  101 | cherry     |    3.20 |
|  102 | banana     |   10.30 |
|  102 | grape      |    5.30 |
+------+------------+---------+
mysql> SELECT s_id, f_name, f_price FROM fruits WHERE s_id NOT IN (101,102);
+------+---------+---------+
| s_id | f_name  | f_price |       # 与IN相反,用来查询不在条件范围内的记录
+------+---------+---------+
|  103 | apricot |    2.20 |
|  104 | berry   |    7.60 |
|  107 | xxxx    |    3.60 |
|  105 | melon   |    8.20 |
|  104 | lemon   |    6.40 |
|  106 | mango   |   15.70 |
|  105 | xbabay  |    2.60 |
|  105 | xxtt    |   11.60 |
|  103 | coconut |    9.20 |
|  107 | xbababa |    3.60 |
+------+---------+---------+

 

 

 

   

以上是关于IN 查询的主要内容,如果未能解决你的问题,请参考以下文章

What's the difference between @Component, @Repository & @Service annotations in Spring?(代码片段

imgwarp.cpp:3143: error: (-215:Assertion failed) _src.total() > 0 in function ‘warpPerspective‘(代码片段

NDK: ant 错误 [javah] Exception in thread "main" java.lang.NullPointerException 多种解决办法(代码片段

SpringBoot启动报错“Consider defining a bean of type ‘xxx.mapper.UserMapper‘ in your configuration.“(代码片段

sql语句中嵌套时候用in 和=有啥区别

[React Testing] Use Generated Data in Tests with tests-data-bot to Improve Test Maintainability(代码片段