登录
首页 >  数据库 >  MySQL

mongodb和mysql单表查询

来源:SegmentFault

时间:2023-01-12 08:44:45 271浏览 收藏

数据库小白一枚,正在不断学习积累知识,现将学习到的知识记录一下,也是将我的所得分享给大家!而今天这篇文章《mongodb和mysql单表查询》带大家来了解一下mongodb和mysql单表查询,希望对大家的知识积累有所帮助,从而弥补自己的不足,助力实战开发!

1.选择表中的若干字段
db.teacher.find({},{_id:0,name:1})
select name from teacher;
2.查询满足条件的元组
(1)比较大小
db.teacher.find({salary : {$gt : 5000}})
select * from teacher where salary > 5000;

db.teacher.find({salary : {$gte : 5000}})
select * from teacher where salary >=5000;

db.teacher.find({salary : {$lt : 5000}})
select * from teacher where salary 5000 AND  salary5000 AND (birthday = "1997-01-01" OR name = "大明");
(3)确定集合
db.teacher.find({birthday:{$in:["1997-01-01","2006-01-01"]}})
select * from teacher where birthday in ("1997-01-01","2006-01-01");
 
db.teacher.find({birthday:{$nin:["2007-01-01","2006-01-01"]}})
select * from teacher where birthday not in ("2007-01-01","2006-01-01");
(4)字符匹配
db.teacher.find({name:/大/})
select * from teacher where name like "%大%";

db.teacher.find({name:/^小/})
select * from teacher where name like "大%";

db.teacher.find({name:{$not:/^明/}})
select * from teacher where name not like "明%";
(5)涉及空值的查询
db.teacher.find({salary:null})
select * from teacher where salary=null;

以上就是《mongodb和mysql单表查询》的详细内容,更多关于mysql的资料请关注golang学习网公众号!

声明:本文转载于:SegmentFault 如有侵犯,请联系study_golang@163.com删除
相关阅读
更多>
最新阅读
更多>
课程推荐
更多>
评论列表