表 结构 id code type 依次是number,varchar,number类型
如何 查出 code 一样 type 为 1 的 记录 大于2
比如 1, 003 ,1
2, 003 ,1
3, 004,2
4, 005,3
5, 006,1
6, 006,1 这里 应该 是 003
006
如何 查出 code 一样 type 为 1 的 记录 大于2
比如 1, 003 ,1
2, 003 ,1
3, 004,2
4, 005,3
5, 006,1
6, 006,1 这里 应该 是 003
006
解决方案 »
- 备份数据库表和表里面的数据!命令我搞忘记了!
- 远程连接数据库出现ora-12154 tns 无法解析指定的连接标识符,但本地连接却没有这样的问题
- 求求大哥大姐了,救命啊.出现Inside isClusterMode,bCluster is :false错误了.
- oracle11g优化
- 关于几张表统计的sql求助,很复杂(我是菜鸟,呵呵),大家帮帮看看,谢谢
- 无法访问系统表tab如何解决??
- ****关于分区表建立的问题!**** “未启用功能:Partitioning“?:(
- 数据量大时怎么解决Insert慢?
- 语句查询问题
- Oracle 9i 中导出的数据文件Expdat.dmp为什么不能导入倒oracle 8i 中?
- 一个delete可以删除2个表的数据吗
- 导入imp文件的问题
from tab
where type='1'
group by id
having count(*)>=2
from tab
where type='1'
group by code
having count(*)>2这样。。
with tb as(
select 1 id,'003' code,1 type from dual union all
select 2,'003',1 from dual union all
select 3,'004',2 from dual union all
select 4,'005',3 from dual union all
select 5,'006',1 from dual union all
select 6,'006',1 from dual)
--以上为提供数据的语句
select code
from (select code,type,count(id) cnt from tb group by code,type)
where cnt>=2COD
---
003
006
--偷学下杨哥的
已写入 file afiedt.buf 1 with tb as(
2 select 1 id,'003' code,1 type from dual union all
3 select 2,'003',1 from dual union all
4 select 3,'004',2 from dual union all
5 select 4,'005',3 from dual union all
6 select 5,'006',1 from dual union all
7 select 6,'006',1 from dual)
8 select code
9 from tb
10 where type=1
11 group by code,type
12* having count(id)>=2
SQL> /COD
---
003
006
from tb a
where a.type=1 and (select count(id) from tb b where a.type=b.type)>2