Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Grouping the output of a SQL query and displaying it

Posted on 2004-10-12
1
Medium Priority
?
159 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 375 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Take a look at these 6 Outlook Email management tools which can augment the working and performance of Microsoft Outlook to give you a more rewarding emailing experience.
Steps to fix error: “Couldn’t mount the database that you specified. Specified database: HU-DB; Error code: An Active Manager operation fail”
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…
Is your data getting by on basic protection measures? In today’s climate of debilitating malware and ransomware—like WannaCry—that may not be enough. You need to establish more than basics, like a recovery plan that protects both data and endpoints.…
Suggested Courses

926 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