sql - Oracle 在 SQL 查询中使用变量
问题描述
我有这样的事情:
With a as (select id from table_a)
select * from table_b where table_b.id > (select min(id) from a)
table_a 是一个包含数百万条记录的巨大表,我不想每次要使用 min(i) 时都通过所有记录来查找 min(i)。我有什么方法可以将 min(id) 存储在变量中并在查询中使用它?像这样的东西:
With a as (select id from table_a),
b as ((select min(id) into min_id from a))
select * from table_b where table_b.id > min_id
解决方案
你的查询应该做你想做的事。但是,如果您真的想确定,请将子查询移至from
子句:
select b.*
from table_b b join
(select min(id) as min_id from a) a
on b.id > a.min_id;
推荐阅读
- android - Firebase A/B 实验是否支持在 Android 上发送“数据”类型通知
- php - 如何避免 substr() 破坏 html 标签?
- python - 将整个句子转换为字符串到列表中而不进行拆分
- spring-boot - 代理设置不适用于 Spring WebClient
- ios - Swift - 如何使用 becomeFirstResponder 跳转到顶部
- python - 用 Beautiful Soup 抓取 Facebook 的点赞、评论和分享
- javascript - 输入过滤器正则表达式单十进制只允许 0 或 5
- java - 带有 jar 加载 main 的 Java docker
- php - 如果他没有登录,如何让用户登录
- python - 将python开发环境库上传到Hi3519 SoC(片上系统)