常规查询
union/union all
select first_name from t_test1 union all select first_name from t_test2;复制
distinct
select distinct first_name from t_test1;复制
like
select * from t_test where first_name like 'zhou%';复制
group by/order by
select first_name,count(*) from t_test1 group by first_name order by 2;复制
having
select e.id, count(e.id), round(avg(e.score), 2) from t_test1 e group by e.id having avg(e.score) > (select avg(score) from t_test1);复制
聚合查询
select first_name,count(*) from t_test group by first_name; select sum(score) from t_test;复制
分页查询
select * from t_test1 limit 10; select * from t_test1 limit 10,10;复制
关联查询
内连接
select t1.id,t1.first_name,t2.last_name from t_test1 t1,t_test2 t2 where t1.id = t2.id;复制
左连接
select t1.id,t1.first_name,t2.last_name from t_test1 t1 left join t_test2 t2 on t1.id = t2.id and t1.id=100;复制
右连接
select t1.id,t1.first_name,t2.last_name from t_test1 t1 right join t_test2 t2 on t1.id = t2.id and t1.id=100;复制
子查询
标量子查询
select e.id, e.first_name, (select d.first_name from t_test2 d where d.id = e.id) as first_name from t_test1 e;复制
派生子查询
select a.first_name, b.last_name from t_test1 a, (select id,last_name from t_test2) b where a.id = b.id;复制
in/not in子查询
select * from t_test1 where id in(select id from t_test2);复制
exists/not exists子查询
select * from t_test1 A where exists (select 1 from t_test2 B where B.id = A.id);复制
「喜欢这篇文章,您的关注和赞赏是给作者最好的鼓励」
关注作者
【版权声明】本文为墨天轮用户原创内容,转载时必须标注文章的来源(墨天轮),文章链接,文章作者等基本信息,否则作者和墨天轮有权追究责任。如果您发现墨天轮中有涉嫌抄袭或者侵权的内容,欢迎发送邮件至:contact@modb.pro进行举报,并提供相关证据,一经查实,墨天轮将立刻删除相关内容。
评论
相关阅读
数据库国产化替代深化:DBA的机遇与挑战
代晓磊
1086次阅读
2025-04-27 16:53:22
数据库,没有关税却有壁垒
多明戈教你玩狼人杀
542次阅读
2025-04-11 09:38:42
【活动】分享你的压箱底干货文档,三篇解锁进阶奖励!
墨天轮编辑部
435次阅读
2025-04-17 17:02:24
国产非关系型数据库 Eloqkv 初体验
JiekeXu
155次阅读
2025-04-10 23:51:35
繁华落尽,烟火人间,3000万相亲局的行业百态
多明戈教你玩狼人杀
139次阅读
2025-04-22 11:53:46
大家也一起去捕捉宝可梦吧!
多明戈教你玩狼人杀
128次阅读
2025-04-14 11:41:47
从Oracle和TiDB的HTAP说起
薛晓刚
101次阅读
2025-04-07 19:09:00
Kingbase逻辑备份与恢复标准化实施文档
Digital Observer
93次阅读
2025-04-11 10:11:46
AI 时代, 需要什么样的数据底座?
ProtonBase
60次阅读
2025-04-24 17:28:07
【磐维数据库】改造案例分享(一):Mariadb到Panweidb对象改造
钟一
41次阅读
2025-04-11 14:47:18