MySQL高级语句(一)
source link: https://blog.csdn.net/m0_51160032/article/details/121667420
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
目录
一、SQL高级语句
1.导入文件至数据库
2. select
显示表格中的一个或者多个字段中所有的信息
3. distinct
查询不重复记录
4.where
where 有条件的查询
5.and;or
and 且 ; or 或
6.in
显示已知值的资料
7.between
显示两个值范围内的资料
8.like 通配符
通配符通常是和 like 一起使用
9. order by
order by 按关键字排序
10.函数
10.1数学函数
10.2 聚合函数
10.3字符串函数
1)trim
2)length
3)replace
select replace(name,'ua','hh') from students;
4)concat
4)substr
11.group by
-
对group by 后面的字段的查询结果进行汇总分组,通常是结合聚合函数一起使用的
-
group by 有一个原则,就是select 后面的所有列中,没有使用聚合函数的列必须出现在 group by 的后面。
12.having
-
having:用来过滤由group by语句返回的记录集,通常与group by语句联合使用
-
having语句的存在弥补了where关键字不能与聚合函数联合使用的不足。如果被SELECT的只有函数栏,那就不需要GROUP BY子句。
-
要根据新表中的字段,来指定条件
13.别名
栏位別名 表格別名
14.连接查询
1)inner join(等值相连)
只返回两个表中联结字段相等的行
SELECT * FROM students A INNER JOIN scores B on A.stuid = B.stuid;
2)left join(左联接)
返回包括左表中的所有记录和右表中联结字段相等的记录
select * from scores A left join students B on A.stuid = B.stuid;
3)right join(右联接)
select * from scores A right join students B on A.stuid = B.stuid;
15.子查询
连接表格,在WHERE 子句或HAVING 子句中插入另一个SQL语句
16.EXISTS
-
用来测试内查询有没有产生任何结果类似布尔值是否为真
-
如果有的话,系统就会执行外查询中的SQL语句。若是没有的话,那整个 SQL 语句就不会产生任何结果。
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK