数据库(部分函数)

函数:

单行函数:会对查询中的每一数据进行处理

字符函数

length(列名)

select name,

日期函数:

now() 年月日时分秒

curdate() 年月日

curtime()时分秒

year(日期列)获取指定日期

str_to_date(日期,格式)将指定日期格式化为规定格式

select str_to_date ('2014-1-1','%y-%m-%d') from表名

datediff(curdate(),birthday)计算两个日期间相差的天数

数学函数:

select name ,gender, round(height),cell(1.1),floor(1.9)from 表名

select name, gender, truncate(height,1),height,rand() from 表名

分组函数: 聚合函数 (查询多行返回一行),统计函数

select sum (weight)from 表名(体重求和)

select avg(height)from 表名(身高均值)

select max/min (height) from 表名

select count(*)from 表名(计数)

条件查询

select*from 表名 where条件

select*from team where gender ='男' and height >1.80

or 多个条件满足一个即可

模糊查询

select *from 表名 where 列名 like'关键字%'

eg: select *from team where name like'王%'

in (值1,值2) from表名 再给定值中查找

排序

select*from 表名 where 条件 order by 列名 ASC 升序

select*from team where number >0order by number DESC 降序

一般默认升序

数量限制

limit:对查询的显示结果限制数目

select *from student where number >0 order by number ASC limit 0,3

从第0行,检索到第3行

分组处理:一般根据性别,年龄,职业等不同条件加以限制

把满足某一个条件的数据分到同一个组中,每个组内单独进行处理

select count(*),gender from 表名 group by gender 根据男女性别分组

having count(*)>2 having 条件 是u低分组后的结果进行条件筛选

相关推荐
Databend10 分钟前
只看 PASS 会骗你,6 条 Agent Trace 里的 Coding Agent 评测真相
大数据·数据库·agent
小袁拒绝摆烂19 分钟前
一条 SQL 从 30 秒到 300 毫秒:聊聊 MySQL 的 Hash Join
sql·mysql·哈希算法
Wang's Blog26 分钟前
Java框架快速入门: Spring Security+OAuth2之密码验证规则与自定义注解
java·数据库·spring
少陽君1 小时前
Python 并发编程:IO 等待用线程/asyncio,CPU 计算才用进程
数据库·python·php
这个DBA有点耶1 小时前
VLDB 2026核心议题解读:当负载被AI改写,数据库的内核该往哪走?
数据库·架构·aigc
敲代码的嘎仔1 小时前
自己设计了一个兑换码算法:自增ID + Base32转码 + 按位加权签名 + 异或混淆,面试被追问细节时终于不用慌了
java·数据库·mysql·算法·微服务·面试·职场和发展
shirsl2 小时前
数据开发实时项目问题整理
数据库·sql·big data
bbq粉刷匠2 小时前
数据库设计实践
数据库
java_logo2 小时前
Docker 部署 ClickHouse Server:轻松搭建列式 OLAP 分析数据库平台
数据库·clickhouse·docker·私有化部署·olap·列式数据库·轩辕镜像
盛世宏博智慧档案2 小时前
高速 ETC 门架外场机房温湿度远程监测解决方案
服务器·数据库·php·高度·高速·温湿度