标签:style ddr ble mys app 北京 base 字符 范围
1. 增删改查操作查询:
select * from 表名 where 字段名 运算符 数字/字符;
修改:
update 表名 set 字段名=值,... where 字段名 运算符 数字/字符
删除:
delete from 表名 where 字段名 运算符 数字/字符
2. 运算符
数值比较运算符:
=
!=
>
>=
<
<=
字符比较运算符:
=
!=
逻辑运算符:
and
or
范围内比较:
between and
in
not in
样板:
create database sky;
use sky;
create table m1(
id int(11),
name char(20),
age tinyint(10),
sex enum('男','女'),
score tinyint(10),
address char(20)
) default charset=utf8;
insert into m1 values
(1,'L1',21,'男',90,'北京'),
(2,'L2',19,'男',91,'上海'),
(3,'L3',24,'女',95,'广州'),
(4,'L4',22,'男',89,'广州'),
(5,'L5',20,'女',86,'上海'),
(6,'L6',19,'女',99,'广州');
查找 表里 id在1到小于5之间的人
mysql> select * from m1 where id >=1 and id <5;
+------+------+------+------+-------+---------+
| id | name | age | sex | score | address |
+------+------+------+------+-------+---------+
| 2 | L2 | 19 | 男 | 91 | 上海 |
| 3 | L3 | 24 | 女 | 95 | 广州 |
| 4 | L4 | 22 | 男 | 89 | 广州 |
| 1 | L1 | 21 | 男 | 90 | 北京 |
+------+------+------+------+-------+---------+
4 rows in set (0.00 sec)
字段名 between 值1 and 值2
字段名 in(值1,值2,...)
字段名 not in(值1,值2,...)
查找id在2到5之间的人并且地址在广州的人
mysql> select * from m1 where id between 2 and 5 and address="广州";
+------+------+------+------+-------+---------+
| id | name | age | sex | score | address |
+------+------+------+------+-------+---------+
| 3 | L3 | 24 | 女 | 95 | 广州 |
| 4 | L4 | 22 | 男 | 89 | 广州 |
+------+------+------+------+-------+---------+
2 rows in set (0.00 sec)
或者
mysql> select * from m1 where (id between 2 and 5) and (address="广州");
+------+------+------+------+-------+---------+
| id | name | age | sex | score | address |
+------+------+------+------+-------+---------+
| 3 | L3 | 24 | 女 | 95 | 广州 |
| 4 | L4 | 22 | 男 | 89 | 广州 |
+------+------+------+------+-------+---------+
2 rows in set (0.00 sec)
显示id为1,2,5的人,用 in
mysql> select * from m1 where id in(1,2,5);
+------+------+------+------+-------+---------+
| id | name | age | sex | score | address |
+------+------+------+------+-------+---------+
| 2 | L2 | 19 | 男 | 91 | 上海 |
| 5 | L5 | 20 | 女 | 86 | 上海 |
| 1 | L1 | 21 | 男 | 90 | 北京 |
+------+------+------+------+-------+---------+
3 rows in set (0.00 sec
显示地址不在北京的人
mysql> select * from m1 where address not in ("北京");
+------+------+------+------+-------+---------+
| id | name | age | sex | score | address |
+------+------+------+------+-------+---------+
| 2 | L2 | 19 | 男 | 91 | 上海 |
| 3 | L3 | 24 | 女 | 95 | 广州 |
| 4 | L4 | 22 | 男 | 89 | 广州 |
| 5 | L5 | 20 | 女 | 86 | 上海 |
+------+------+------+------+-------+---------+
4 rows in set (0.00 sec)
显示id为1或2或5地址在上海的和名字为L2的用户
mysql> select * from m1 where id in(1,2,5) and address="上海" or name="L2";
+------+------+------+------+-------+---------+
| id | name | age | sex | score | address |
+------+------+------+------+-------+---------+
| 2 | L2 | 19 | 男 | 91 | 上海 |
| 5 | L5 | 20 | 女 | 86 | 上海 |
+------+------+------+------+-------+---------+
2 rows in set (0.00 sec)
标签:style ddr ble mys app 北京 base 字符 范围
原文地址:http://blog.51cto.com/calabash/2139533