当前位置: 首页 > news >正文

数据库sql语句单表查询

简单的增删改查操作

select count(*) from user where account='admin' and password='123456'


select count(*) from user where account="admin"
insert into user(account,password) values ("admin","777")

update user set password = "666" where account="admin"

delete from student where id = 1


-- 查找

select id,name,age,sex from student

select * from student

where子语句:
-- 运算符
-- =等于
-- >大于
-- <小于
-- >=大于等于
-- <=小于等于
-- !=   <> 不等于

select * from student where age >= 21

select * from student where age <= 21

select * from student where age <> 21

-- 关键字
-- between .. and ...  []   介于..之间
select * from student where id between 2 and 5

-- in  包含
select * from student where id in(1,2,4,6)

-- is null 为null
select * from student where sex is null

-- 逻辑运算符
-- and 并且 
-- or 或者
-- not  非  与 is  in 搭配
select * from student where age >20  and id in(1,2,4,6)

select * from student where age >=20  and age <= 32 and name = "李四"

-- select * from student where age between 20 and 32

select * from student where age >=32 or age<=20  or sex ="女"

select * from student where sex is not null

select * from student where id not in(1,2,4,6)

-- 模糊查找  like  占位符 _代表一位字符 %代表任意位字符

select * from student where name like "_李"//李前边有一位

select * from student where name like "李%"//李后边有多位

select * from student where name like "%李%"//李前后都有多位


limit子语句 限制查询:
-- limit a , b
-- limit b offset a
-- a表示起始索引值,索引从0开始  b代表查询个数
select * from student limit 7,2

从索引为7的位置开始向下查两条

这个索引相当于数组的角标

-- 一页四条
-- 第一页
select * from student limit 0,4
-- 第二页
select * from student limit 4,4
-- 第三页
select * from student limit 8,4

-- 页码page  一页大小 pageSize

select * from student limit (page-1)*pageSize,pageSize

比如浏览器搜索每页有很多条在下边有页码
select * from student where sex = "女" limit 0,4

从性别为女的数据中找出前四条
-- 排序子语句  order by 列名   desc降序|asc升序  (asc可省)

select * from student order by age asc

按照年龄大小降序排序
select * from student where age>21 order by age desc limit 0,4

-- where    order by    limit

写的顺序
-- 分组函数 聚合函数
-- 聚合函数 
-- sum 求和
-- avg 取平均
-- max 取最大值
-- min 取最小值

用法

select min(age) from student min可以用上述函数替换
-- count 取得记录数量  count(字段名) 不统计为null的记录
select count(*) from student
-- group by 分组函数

select class,max(age) from student group by class


select class,max(age) from student where sex = "女" group by class having class = 3

分组之前用where找 分组之后用having找 两者用法完全相同
 

http://www.lryc.cn/news/511513.html

相关文章:

  • Linux高级--2.4.2 linux TCP 系列操作函数 -- 深层理解
  • 科技快讯 | 水滴筹成为民政部指定个人求助网络服务平台;小米超级小爱首次向正式版用户开放;腾讯发布全球首个重症医疗大模型
  • 强化特种作业管理,筑牢安全生产防线
  • 跨语言学习之C++ 和 Python 的赋值操作 (等号“=“) 的区别
  • 【操作系统】如何创建一个守护进程
  • 常见显示方案
  • USB Hub 检测设备
  • 安卓开发使用Gemini高效AI开发-Android Studio 中使用Gemini
  • wangEditor富文本插件在vue项目中使用和媒体上传的实现
  • ESP-IDF学习记录(2)ESP-IDF 扩展的简单使用
  • python中函数的用法总结(二阶段)
  • 一份关于 Ubuntu 系统下代理配置的故障排查笔记
  • 使用 Colyseus 构建多人实时白板应用
  • 【探花交友】SpringCache
  • Spring API 接口加密/解密
  • 漏洞扫描:网络安全的 “体检” 与 “防护指南”
  • 【可靠有效】springboot使用netty搭建TCP服务器
  • 机器视觉中的单线程、多线程与跨线程:原理与应用解析
  • 0040__Linux内核4.14版本——drm框架分析(1)——drm简介
  • 珞珈一号夜光遥感数据地理配准,栅格数据地理配准
  • 【GlobalMapper精品教程】091:根据指定字段融合图斑(字段值相同融合到一起)
  • Quartz任务调度框架实现任务动态执行
  • ESP-IDF学习记录(1)ESPIDF环境安装,框架了解,资料整理
  • Windows系统提示synsoacc.dll文件报错要怎么解决?
  • React(一)—— router/useRef/useState
  • ipad如何直连主机(Moonlight Sunshine)
  • 音视频入门知识(二)、图像篇
  • v-if 和 v-show 的区别
  • 解密MQTT协议:从QOS到消息传递的全方位解析
  • Java-02 深入浅出 MyBatis - MyBatis 快速入门(无 Spring) POM Mapper 核心文件 增删改查