MySQL数据库(三)——查询

SQL基本语句格式:

select 属性列表 from 表名 [where 条件表达式1]

[group by 属性名 [Having 条件表达式2]]

[order by 属性名 [ASC | DESC]]

1、带in的子查询

[not] in (元素1、元素2……);

2、带between and的范围查询

[not] between 取值1 and 取值2

3、带like的通配符配置查询

[not] like '字符串'

通配符:

(1)%:表示0个或任意长度的字符串。

(2)_:只表示单个字符。

4、空值查询

is [not] null

5、带and的多条件查询

条件表达式1 and 条件表达式2

6、带or的多条件查询

条件表达式1 or 条件表达式2

7、去重查询

select distinct 属性名 from 表名;

8、对结果排序

order by 属性名 ASC | DESC;

ASC:升序

DESC:降序

默认升序(ASC)

9、分组查询

group by 属性名 [having 条件表达式]

(*问题)distinct和group by的不同?

10、limit分页查询

limit 数据;//只有一个参数,表示不指定起始位置为limit数据

limit 数据1(起始位置) 数据2(偏移量);//有两个参数,第一个表示起始位置,第二个表示偏移量

猜你喜欢

转载自blog.csdn.net/weixin_42479293/article/details/94738351