mysql一些语法记录

  1. count:

    count(*) 符合条件所有行数;

    count(列名) 符合条件行数排除null;

  2. group by

    select sum(amount) from test where status = 1 group by dept having amount >= 100

    顺序:

    group by 对 where过滤后的数据进行分组;(分组字段去重后有几个,结果就有几行数据;分组字段可以有多个,如:group by a,b

    函数如:sum(),count()等对分组后的每组数据进行计算 (有几组数据就有几条数据)

    having: 如果有having条件,having后是对分组计算后的数据进行过滤

相关推荐
月光水岸New几秒前
Ubuntu 中建的mysql数据库使用Navicat for MySQL连接不上
数据库·mysql·ubuntu
狄加山6752 分钟前
数据库基础1
数据库
我爱松子鱼5 分钟前
mysql之规则优化器RBO
数据库·mysql
chengooooooo30 分钟前
苍穹外卖day8 地址上传 用户下单 订单支付
java·服务器·数据库
Rverdoser1 小时前
【SQL】多表查询案例
数据库·sql
Galeoto2 小时前
how to export a table in sqlite, and import into another
数据库·sqlite
人间打气筒(Ada)2 小时前
MySQL主从架构
服务器·数据库·mysql
leegong231112 小时前
学习PostgreSQL专家认证
数据库·学习·postgresql
喝醉酒的小白2 小时前
PostgreSQL:更新字段慢
数据库·postgresql
敲敲敲-敲代码2 小时前
【SQL实验】触发器
数据库·笔记·sql