A.B两张表,找出ID字段中,存在A表,但是不存在B表的数据,A表总共13W数据,去重后大约3万条数据,B表有2W条数据,且B表的ID有索引. 方法一 使用not in,容易理解,效率低. select distinct a.id from a where a.id not in(select id from b) 1 方法二 使用left join … on ….,’b.id is null’,表示左连接之后在b.id字段为null的记录 select a.id from a left joi
ORACLE中如何找出大表分布在哪些数据文件中? 在ORACLE数据中,我们能否找出一个大表的段对象分布在哪些数据文件中呢? 答案是可以,我们可以用下面脚本来找出对应表的区.段分别位于哪些数据文件中 SET PAGESIZE 60; COL SEGMENT_TYPE FOR A12; COL FILE_NAME FOR A64; COL SEGMENT_NAME FOR A24; COL TABLESPACE_NAME FOR A24; COL SEGMENT_OWNER FOR A12;
本文是受网文 <一次非常有意思的SQL优化经历:从30248.271s到0.001s>启发而产生的. 网文没讲创建表的数据过程,我帮他给出. 创建科目表及数据: CREATE TABLE tb_course ( id NUMBER not null primary key, name NVARCHAR2(10) not null ) Insert into tb_course select rownum,dbms_random.string('*',dbms_random.value(6,10
EMP表是Oracle测试账户SCOTT中的一张雇员表,首先,我们来看看emp表的数据 SQL> select * from emp; EMPNO ENAME JOB MGR HIREDATE SAL COMM DEPTNO ----- ---------- --------- ---------- --------- ---------- ---------- ---------- SMITH CLERK ALLEN SALESMAN WARD SALESMAN JONES MANAGER M
测试的工作中,经常会遇到项目交接或者搭建一个新的测试环境,而创建oracle数据库用户及表空间时,需要提前找出脚本中的 数据库用户名和表空间名,所以自己写了一个python脚本,自动找出sql脚本中的数据库用户名和表空间名以及对应出现的次数. 脚本如下: #encoding=utf-8 import redef FindUsernameOrTableplace(*dir_part): username_num={} tablespace_num={} try: for i in dir_part
有些时候,有些作业遇到问题执行时间过长,因此我写了一个脚本可以根据历史记录,找出执行时间过长的作业,在监控中就可以及时发现这些作业并尽早解决,代码如下: SELECT sj.name , sja.start_execution_date,DATEDIFF (SECOND ,sja.start_execution_date,GETDATE() ) AS ExecutedMin,ja.AvgRuntimeOnSucceed FROM msdb.dbo.sysjobactivity AS
Given an array of integers where 1 ≤ a[i] ≤ n (n = size of array), some elements appear twice and others appear once. Find all the elements of [1, n] inclusive that do not appear in this array. Could you do it without extra space and in O(n) runtime?
Given an array of integers, 1 ≤ a[i] ≤ n (n = size of array), some elements appear twice and others appear once. Find all the elements that appear twice in this array. Could you do it without extra space and in O(n) runtime? Example: Input: [4,3,2,7,
Median is the middle value in an ordered integer list. If the size of the list is even, there is no middle value. So the median is the mean of the two middle value. Examples: [2,3,4] , the median is 3 [2,3], the median is (2 + 3) / 2 = 2.5 Design a d
在一个SQL Server表中一行的多个列找出最大值 有时候我们需要从多个相同的列里(这些列的数据类型相同)找出最大的那个值,并显示 这里给出一个例子 IF (OBJECT_ID('tempdb..##TestTable') IS NOT NULL) DROP TABLE ##TestTable CREATE TABLE ##TestTable ( ID ,) PRIMARY KEY, Name ), UpdateByApp1Date DATETIME, UpdateByApp2Date DAT
就是找x+y=-z的组合 转化为找出值为-z满足x+y=-z的组合 解法一: 为了查找,首先想到排序,为了后面的二分,nlogn, 然后x+y的组合得n^2的复杂度,加上查找是否为-z,复杂度为nlogn + n^2 * logn 解法二: 还是先从小到大排序 nlogn 假设数组排序后为 a b c d e f 我们还是要找x+y=-z 会发现-z存在的可能只能是a+f和b+e,不会存在a+e和b+f这种情况(这里很重要,保证了算法的正确性),所以两个指针一头一尾往中间扫,肯定能找出来 fis