2014-10-28 25 views
0

我有Oracle 11 G數據庫。在Oracle中id相同時連接記錄

我的表CHATUSERS看起來是這樣的:

UserId - Identifier 
SeqNum - Order of chat conversation 
ChatText - Chat Text 
DateAdded - DateTime Chat conversation happened. 

的用戶可以在一天內多個聊天會話。 我想結合每人每天的所有ChatText。

例子:

UserId SeqNum DateAdded ChatText 
-------------------------------- 
1  1  28-OCT-14 Hey, How are You? 
1  2  28-OCT-14 Do you have a minute? 
1  3  28-OCT-14 Wanted to talk to you about something. 
1  1  25-OCT-14 Congratulations! 
1  2  25-OCT-14 on your promotion 

所以SELECT查詢將返回的結果爲:我如何做到這一點

UserId, DateAdded and CompleteText 
1 28-OCT-14 Hey, How are You? Do you have a minute? Wanted to talk to you about something. 
1 25-OCT-14 Congratulations! on your promotion 

+0

你應該看看LISTAGG()。 – gmiley 2014-10-28 19:17:34

+0

究竟哪個11g版本?如果您使用11gR2,則可以查看「LISTAGG」,如果是11gR1,答案將會不同。 – 2014-10-28 19:18:20

+0

Oracle數據庫11g企業版版本11.2.0.4.0 - 64位生產 – Ram 2014-10-28 19:20:12

回答

0
select userid, dateadded, listagg(chattext, ' ') within group (order by seqnum) 
from chatusers 
group by userid, dateadded; 
相關問題