Solved

Grouping the output of a SQL query and displaying it

Posted on 2004-10-12
1
155 Views
Last Modified: 2010-04-01
Hi all,

I have a query with a resultset similar to this:

type | amount
1 | a
1 | b
1 | c
2 | a
2 | b
3 | a

I want the display to look like this:

1 | a
   | b
   | c
2 | a
   | b
3 | a

This is similar to coldfusion and the cfoutput group attribute. Basically, I want anything with duplicates to be removed from the output (given that they are ordered correctly in the query). It is not only this query, it should apply to much larger queries with more columns.

Is there any type of tool to do this or do I have to write something that always checks the previous row's value and then displays whether or not it was the same as the current row?

thank you very much.

Jin
0
Comment
Question by:neojin80
1 Comment
 
LVL 19

Accepted Solution

by:
Kuldeepchaturvedi earned 125 total points
ID: 12296823
I think you can do this with a loop while creating the table.
Assuming that you have got them in ordered form.
<table>
<%
int myval=-1;
while(rs.next())
{%>
<tr>
<%
if(myval==-1 or myval=rs.getString(1))
{
myval=rs.getint(1)
%>
<td><%=myval%></td>
<%
}else
{%>
<td></td>
<%}
//rest of the processing.
}
%>

This should do the job
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

There's a lot of hype surrounding blockchain technology. Here's how it works and some of the novel ways it' s now being used - including for data protection.
Ransomware continues to grow in reach and sophistication, putting data everywhere at risk. Learn how to avoid being caught in its sinister clutches with these 11 key tips.
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

821 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question