mysql 中with的用法(1)

mysql 中with的用法

1、案例一:

建表:

bash 复制代码
CREATE TABLE employees (
    employee_id INT PRIMARY KEY,
    first_name VARCHAR(50),
    last_name VARCHAR(50),
    salary INT
);
bash 复制代码
INSERT INTO employees (employee_id, first_name, last_name, salary)
VALUES 
    (1, 'John', 'Doe', 50000),
    (2, 'Jane', 'Doe', 55000),
    (3, 'Jim', 'Smith', 60000),
    (4, 'Sarah', 'Johnson', 65000),
    (5, 'Tom', 'Brown', 70000);
select  * from employees e 

构建临时表:

sql 复制代码
with moth_saleary as(
select e.employee_id ,e.first_name ,
e.last_name ,e.salary ,salary/12 as moth_saleary from employees e 
)

select * from moth_saleary

#salary/12 as moth_saleary 这个可以和构建的临时表名称一样,也可以不一样,这个临时表只是将查询结果包了起来。作为结果展示了出来

查询结果:

相关推荐
ZGG00317 分钟前
线程池详解:从 7 大参数到生产避坑
java·数据库·后端
龙亘川20 分钟前
数智赋能退役军人服务:V1.0 系统搭建全生命周期闭环服务体系
大数据·数据库·人工智能
zhangguojia71 小时前
权限弹窗点击允许的授权流程
运维·服务器·数据库
jnrjian1 小时前
Postgres 序列(sequence)的权限
数据库·postgresql
风禾万里1 小时前
【无标题】
数据库
镜舟科技1 小时前
为什么 Text-to-SQL 总是停在 Demo?
数据库·sql·demo·text-to-sql·镜舟科技·mip·语义视图
人生苦短1281 小时前
Oracle RAC 日常管理+排错命令大全
数据库·oracle
镜舟科技1 小时前
从 DBA 经验到 Agent:镜舟如何构建生产级智能排障体系
数据库·agent·dba·skill·devops agent·mirrorship
瀚高PG实验室1 小时前
HAC 集群主节点状态在starting、running之间频繁切换
运维·数据库·postgresql·瀚高数据库
其实防守也摸鱼1 小时前
教育信息技术应用创新---基础软件信息赛
运维·服务器·数据库·github·copilot