页次: 1
首先创建一个表
http://www.ipbbs.net/viewtopic.php?id=165
条件查询用 where , 用于判断有 有 = , !=, < ,<=, > , >=, between , in , like
条件中也可以用逻辑词, or, and, 进行查询
查询名字是aaa
mysql> select * from goods where g_name='aaa'; +------+--------+------+---------+ | g_id | g_name | v_id | g_price | +------+--------+------+---------+ | 1 | aaa | 1 | 1.10 | | 2 | aaa | 2 | 2.10 | | 3 | aaa | 3 | 3.10 | +------+--------+------+---------+ 3 rows in set (0.00 sec)
查询价格大于7元的
mysql> select * from goods where g_price > 7; +------+--------+------+---------+ | g_id | g_name | v_id | g_price | +------+--------+------+---------+ | 7 | ccc | 1 | 7.10 | | 8 | ccc | 2 | 8.10 | | 9 | ccc | 3 | 9.10 | +------+--------+------+---------+ 3 rows in set (0.00 sec)
查询价格在 5元和7元之间的
mysql> select * from goods where g_price between 5 and 7; +------+--------+------+---------+ | g_id | g_name | v_id | g_price | +------+--------+------+---------+ | 5 | bbb | 2 | 5.10 | | 6 | bbb | 3 | 6.10 | +------+--------+------+---------+ 2 rows in set (0.00 sec)
in 是也条件
mysql> select * from goods where g_price in (5, 7); Empty set (0.00 sec)
in 是确定是否在 in 的集中的。
mysql> select * from goods where g_price in (5.10, 6.10, 2.0); +------+--------+------+---------+ | g_id | g_name | v_id | g_price | +------+--------+------+---------+ | 5 | bbb | 2 | 5.10 | | 6 | bbb | 3 | 6.10 | +------+--------+------+---------+
like 用于相似 有两个特殊字符 %, _
% 表示任意多个或者0个字符, _ 任意一个字符
mysql> select * from goods where g_price like '5%'; +------+--------+------+---------+ | g_id | g_name | v_id | g_price | +------+--------+------+---------+ | 5 | bbb | 2 | 5.10 | +------+--------+------+---------+ 1 row in set (0.00 sec)
查询名字不是 ‘aaa' 的产品,并且大于9的
mysql> select * from goods where g_name != 'aaa' and g_price > 9; +------+--------+------+---------+ | g_id | g_name | v_id | g_price | +------+--------+------+---------+ | 9 | ccc | 3 | 9.10 | +------+--------+------+---------+ 1 row in set (0.02 sec)
ipbbs.net
离线
页次: 1