select doc_id, distinct person form ... 这样? Oracle报错...
解决方案 »
- 【遇到大麻烦,如何查询oracle的操作日志】
- 求twitter、饭否这样微博的数据库表结构设计和分析
- 大家来聊聊同样表结构的大量数据对比解决方法
- oracle 从无基础到马马虎虎可以任职dba的基本工作一般要多久?
- 如果找回sys/system密码?
- 很急的一个关于数据库的问题!!!
- OracleOraHome92Agent 启动问题
- 数据库查询时,如果表内有a1,a2,a3...到a12的字段,在查询时我可不可以写成"select a1~a12 "?
- oracle数据导入问题:创建的对象带有编译警告
- 简单问题~~
- 怎样才能启动数据库的监听器?在线急等!!!!
- 急急急,在線等,請幫忙看看一個查詢語句 謝謝
你可以这样
select distinct person,doc_id form ...
大家能理解我说的吗?谢谢
在代码中就很好控制了
(select min(id) as mid from diekiss group by doc_id,person) p
where m.id = p.mid and doc_id = 1
order by doc_id,person
;
group by person,message having doc_id=1
(select min(id) as mid from diekiss group by doc_id,person) p
where m.id = p.mid
order by doc_id,person
;
(select min(id) as mid from diekiss group by doc_id,person) p
where m.id = p.mid
order by doc_id,person
;
select * from table t1 where not exists (select * from table where dco_id=1 and person=t1.person and id<t1.id) and doc_id=1或者用分析函数
CREATE TABLE ZHOUXY.T_BBS
(
ID NUMBER(2,0),
DOC_ID NUMBER(2,0),
PERSON VARCHAR2(10),
MESSAGE VARCHAR2(50)
)
/2。测试数据
ID DOC_ID PERSON MESSAGE
1 1 mike hello
2 1 tom good
3 2 tom ok
4 1 tom goodbye
5 2 mike hi
6 1 kate yes
3。SQL文SELECT
ID ,
DOC_ID ,
PERSON ,
MESSAGE
FROM
(
SELECT
ID ,
DOC_ID ,
PERSON ,
MESSAGE ,
RANK ( ) OVER ( PARTITION BY DOC_ID ,
PERSON
ORDER BY
DOC_ID ,
PERSON ,
ID ) RANK
FROM
T_BBS
WHERE
DOC_ID = 1 )
WHERE
RANK =1
ORDER BY
ID4。测试结果ID DOC_ID PERSON MESSAGE
1 1 mike hello
2 1 tom good
6 1 kate yes