oracle 大表查询 这个表有几千万条数据
发布网友
发布时间:2022-04-14 01:53
我来回答
共4个回答
热心网友
时间:2022-04-14 03:22
其实,很简单啊,不要把问题想复杂了
我们有union all啊
select a,c,g from item
where k=4
group by a,c,g
having count(*)>1
union all
select a,c,g from item
where k<>4
group by a,c,g
having count(*)=1;
热心网友
时间:2022-04-14 04:40
select *
from tab t
where exists (select 1 from tab where a = t.a and c = t.c and g = t.g and k = 4)追问太慢了出不来。因为item里面有几千万条数据,通过地区和时间可以缩小到几万条(site=1,date=2012),要怎么写?
select *
from item(site=1 and date=2012) t
where exists (select 1 from tab where a = t.a and c = t.c and g = t.g and k = 4)
追答你这种情况,可以考虑建立site = 1, date = 2012的视图,效果会好很多的
也可以尝试这个
select *
from (select * from tab where site = 1 and date = 2012) t
where exists (select 1 from tab where a = t.a and c = t.c and g = t.g and k = 4)
热心网友
时间:2022-04-14 06:15
select a, c, g from item
where k=4 and a=c and a=k
热心网友
时间:2022-04-14 08:06
在对应字段创建索引,结合一楼的SQL,效率应该还是可以滴