Solved

Grouping the output of a SQL query and displaying it

Posted on 2004-10-12
1
152 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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
How to write service layer in Spring ? 4 273
password protect pdf 11 72
doubleChar java challenge 7 97
equalIsNot  challenge 43 117
A safe way to clean winsxs folder from your windows server 2008 R2 editions
Is your Office 365 signature not working the way you want it to? Are signature updates taking up too much of your time? Let's run through the most common problems that an IT administrator can encounter when dealing with Office 365 email signatures.
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…

757 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now