当前位置:网站首页>下面这段SQL能否用索引优化查询性能
下面这段SQL能否用索引优化查询性能
2022-04-22 06:16:00 【CSDN问答】
这段SQL能否从索引方面进行优化,然后写法尽量不变,因为拼接出来的。
select * from tab_A awhere (exists (select 1 from (select cst_id, sum(decode(data_dt,'202112',fin_bal,0)) + sum(decode(data_dt,'202112',def_bal,0)) - sum(decode(data_dt,'202110',fin_bal,0)) - sum(decode(data_dt,'202110',def_bal,0)) as amt from tab_B where data_dt in ('202112','202110') group by cst_id) b where b.amt > 10000 and a.cst_id = b.cst_id) );
采纳答案:
建议用having替代where条件,减少一层嵌套。然后建议用join替代这个exists条件。因为很明显里面的这个sql才应该是主驱动表,条件都是基于b表的,应该先确定要查哪些cst_id后,再用这些cst_id查a表。而不是针对a表的每一行去查哪些cst_id满足条件
版权声明
本文为[CSDN问答]所创,转载请带上原文链接,感谢
https://ask.csdn.net/questions/7692090
边栏推荐
- LaTex中插入图片报错Unknown graphics extension: .1.jpg. }
- 1. Compile the following three modules of student information management system: and detect the implementation. 1. Add student information 4. Query student information 5. Query all student information
- Beyond compare solution to "authorization key has been revoked"
- [number theory] congruence (2): inverse element
- 带环链表详解
- 树+二叉树 详解 详解 +Top-k问题
- Unknown graphics extension:. 1 jpg. }
- 区间求和的问题——差分
- 美团春招暑期实习笔试——20220312
- SQL Server quick start
猜你喜欢

LeetCode - 6 - (字符串相乘、下一個更大元素<ⅠⅡⅢ>、k個一組翻轉鏈錶)

在类加载的过程中,类变量的分配区域和实例变量的分配区域不一样

LeetCode - 4 - (接雨水、无重复字符的最长子串、分发糖果、二叉树的<前中后层>序遍历)

Beyond compare solution to "authorization key has been revoked"

synchronized锁优化的一些机制(锁升级)

Add author photos and author profiles to latex

字节暑期实习一面——20220304

队列(详解)——手撕队列习题

win10修改命令行默认字体

Interviewers often ask about the general process and special circumstances of object allocation
随机推荐
L2-001 紧急救援 (最短路Dijkstra的扩展 - 最短路径数&路径最大权值)
使用Feign做远程调用的注意点
2021学习计划
【数论】素数(四):数的分解(Pollard-rho)
296 · 数组去重
友情链接汇总qwq
美团春招暑期实习笔试——20220312
[number theory] congruence (7): fast power, fast power of matrix
【数论】素数(二):素数筛法(埃式筛、欧拉筛、区间筛)
Points for attention in Modelsim simulation acceleration
Define an abstract role class with name, age, gender, hobbies and other member variables. It is required to hide all variables as far as possible (private if possible), and then read and write each va
Vivado generates and invokes EDF netlist files
顺序表之高速缓存命中率
链表习题详解
二叉树链式结构操作LeetCode+牛客(详解)
When latex uses the template, the caption title of the picture cannot be left aligned
JVM中的逃逸分析,可以实现不在堆上分配内存
If an error is reported, process the ES6 filter to filter the array
(1) Download and installation of SQL Server
Relationship between A5 transceiver signal VOD and pre emphasis adjustment