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 这个可以和构建的临时表名称一样,也可以不一样,这个临时表只是将查询结果包了起来。作为结果展示了出来

查询结果:

相关推荐
l1t19 分钟前
DeepSeek总结的DuckLake 入门
数据库
Joseph Cooper28 分钟前
RAG 与 AI Agent:智能体真的需要检索增强生成吗?
数据库·人工智能·ai·agent·rag·上下文工程
light blue bird31 分钟前
主子端台二分法任务汇总组件
前端·数据库·.net·桌面端winform
DevilSeagull1 小时前
MySQL(2) 客户端工具和建库
开发语言·数据库·后端·mysql·服务
小李来了!1 小时前
Navicate/plsql连接Oracle数据库教程
数据库·oracle
苍煜1 小时前
慢SQL优化实战教学
java·数据库·sql
zhaoyong2222 小时前
MySQL 存储过程中字符集与排序规则不匹配导致查询性能下降的解决方案
jvm·数据库·python
sinat_383437362 小时前
golang如何从Python转型Go开发_golang从Python转型Go开发攻略
jvm·数据库·python
远洪2 小时前
claude code 国内安装使用
数据库·mysql
雨辰AI2 小时前
SpringBoot3 + 人大金仓 V9 微服务监控实战|Prometheus+Grafana+SkyWalking 全链路监控
数据库·后端·微服务·grafana·prometheus·skywalking