暂无图片
暂无图片
暂无图片
暂无图片
暂无图片

【StoneDB】查询语句

原创 Winter 2022-07-26
210

常规查询

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进行举报,并提供相关证据,一经查实,墨天轮将立刻删除相关内容。

评论