473,473 Members | 1,456 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

problem in writing a Query

37 New Member
Hi,
I have a table
SQL> select * fom temp;
FID TID RN
---------- ---------- ----------
1 2 1
1 3 2
1 4 3
2 1 1
2 5 2
3 1 1
3 6 2
3 7 3
4 1 1


Now i want the o/p like this

FID TID's
------ ---------------------------
1 2,3,4
2 1,5
3 1,6,7
4 1

Any Help?

thank you
Jan 31 '08 #1
1 1306
amitpatel66
2,367 Recognized Expert Top Contributor
Hi,
I have a table
SQL> select * fom temp;
FID TID RN
---------- ---------- ----------
1 2 1
1 3 2
1 4 3
2 1 1
2 5 2
3 1 1
3 6 2
3 7 3
4 1 1


Now i want the o/p like this

FID TID's
------ ---------------------------
1 2,3,4
2 1,5
3 1,6,7
4 1

Any Help?

thank you
Expand|Select|Wrap|Line Numbers
  1.  
  2. SELECT * FROM
  3. (SELECT fid,sn, row_number() over(partition by fid order by fid,sn desc) rn from
  4. (SELECT fid, SUBSTR(SYS_CONNECT_BY_PATH(rid,','),2) sn  FROM
  5. (select fid,rid,row_number() OVER(PARTITION BY fid ORDER BY FID) rn  FROM
  6. (select 1 as fid, 2 as rid from dual
  7. UNION
  8. select 1, 3 from dual
  9. union
  10. select 1, 4 from dual
  11. UNION
  12. select 2, 1 from dual
  13. UNION
  14. SELECT 2, 2 from dual
  15. UNION
  16. SELECT 3, 4 from dual
  17. UNION
  18. SELECT 3, 6 FROM Dual)) 
  19. CONNECT BY rn = PRIOR rn - 1
  20. AND PRIOR fid = fid
  21. ORDER BY sn desc, fid desc))
  22. WHERE rn = 1
  23.  
  24. --output
  25.  
  26. FID    SN    RN
  27. 1    4,3,2    1
  28. 2    2,1    1
  29. 3    6,4    1
  30.  
  31.  
The above query looks slightly complex becuase i dont have a table structure and had to make it work using dual statements for the data.
Jan 31 '08 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Syed Ghayas | last post by:
Hi, I've been having problem writing a cookie. Everything goes ok but when I supply the .Path property to "/" It just write the cookie when there is no cookie present, but when I try to update the...
3
by: acdevteam | last post by:
Hello Everyone, We are a dev team very new to Access, and so far we have gotten excellent support from this group. We have a question about writing a query. Here is the situation: We have a...
5
by: vijay.db | last post by:
Hi Group, I'm running DB2 UDB Enterprise Edition V7.1 in AIX 4.3.3.0. And database backups goes to the TSM server. We have the following TSM Client API installed in the server: ...
2
by: weird0 | last post by:
Hi! On the recommendation of one of the MVP's on this group....... I tried writing parametrized queries. But the fucking thing does not work and it does not update the data in the table. I...
19
by: rmr531 | last post by:
First of all I am very new to c++ so please bear with me. I am trying to create a program that keeps an inventory of items. I am trying to use a struct to store a product name, purchase price,...
2
by: grabit | last post by:
Hi Mary this is the problem child (query) <!---Query db for page info---> <cfquery name="showtopics" datasource="parrots"> SELECT categories.catID, threads.threadID, threads.posttype,...
1
navneetkaur
by: navneetkaur | last post by:
can any1 help me plz in writing sql query.....m problem is i have to combine two tables in 1 table m having desicode 'd in other table m having desicode 'd division name i jst want to display all...
2
manoj9849967222
by: manoj9849967222 | last post by:
Hi All I have a problem with query. I have designed a simple query which sould give me itemwise total qty sales during a given period. the fields in the query are startdate,...
0
by: viki1967 | last post by:
Problem with query ASP and MySQL Hi there. I have this fields in the tbl (mysql) : - ID (unique) - user_name (text) - Date (yyyy-mm-dd) - Description (text - case A or B or C -)
1
by: vapanchamukhi | last post by:
hi.... i want to write the query select * from user where name = "richard"; in perl the string richard i have taken that in the variable $name. i have written the query as below $sth =...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.