sql常用指令 / mongoDB常用指令
sql语句本身大小写不敏感,但是操作的数据本身大小写敏感
【增】
1.insert into userInfo (name, age, sex, country) values ('张三',18,'male','cn')
--- 根据表格格式插入数据
【查】
-
select* from userInfo
--- 查询userInfo所有记录 -
select * from userInfo where age = 22
--- 查询userInfo中age=22记录 -
select * from userInfo where age >22
--- 查询userInfo中age>22记录 -
select * from userInfo where age <22
--- 查询userInfo中age<22记录 -
select * from userInfo where age >= 25
--- 查询userInfo中age>=25记录 -
select * from userInfo where name = ‘zhangsan’ and age = ‘22’
--- 查询userInfo中name为zhangsan,且age为22的数据
模糊查询
1.select * from userInfo where name like ‘%car%’
--- 查询userInfo中,name含有car的数据
2.select * from userInfo where name like ‘car%’
--- 查询userInfo中,name以car开头的数据
查询结果字段过滤
1.select name, age from userInfo
--- 查询userInfo中,返回name与age字段信息
2.select name, age from userInfo where age >25
--- 查询userInfo中,年龄大于25,返回name与age字段信息
查询结果排序
1.select name,height from student order by height desc,name asc
--- 查询student表格,返回name与age字段信息,且根据 height 降序排序,再按 name 升序排序
2.select * from userInfo order by age
--- 查询userInfo中所有数据,按照年龄排序
返回特定范围内的5条信息
1.selecttop 5 * from userInfo
--- 查询 userInfo 中返回前5条数据
-
select * from userInfo where id not in ( selecttop 10 * from userInfo )
--- 返回10条后的数据 -
select * from userInfo limit 11,15
--- 查询userInfo中,第11到第15条的所有数据信息
返回特定时间内的数据
1.select * from userInfo where dDate>='2010-11-05' and dDate<='2010-11-15'
或查询
1.select * from userInfo where age = 22 or age = 25
查询第一条数据
1.selecttop 1 * from userInfo
--- 查询 userInfo 中第一条数据
返回查询数据条数
1.select count(*) from userInfo where age >= 20
--- 查询userInfo中age大于等于20的数据条数
【改】
1.update userInfo set age=50,sex='female' where name = ‘Lisi’
--- 更新name为Lisi的数据,年龄50,性别female
【删除】
1.delete from userInfo where name='Lisi' and sex='male'
--- 删除name为Lisi且sex为male的数据
网友评论