473,396 Members | 1,917 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

sort data from a table by count value's?

Is it possible so sort data from a table based on the count results?

I have the following

<% set rs = db.execute("Select * from tbleventinfo order by ename")
while not rs.EOF
tmp = rs("eid")
set rs1 = db.execute("Select count(eid) from tbleventdj where eid = " &
tmp)
if rs1.EOF = false then
total = rs1.fields.item(0)
else
total = 0
end if
set rs1 = Nothing
echo rs("ename") & "(" & total & ")"

rs.moveNext
if rs.EOF = false then Response.write "<br>"
wend
set rs = Nothing
%>

which works fine. but as you can see it sorts it all out bases on the
ename...

Any help apriciated!!

Willem-Jan Selen
Jul 19 '05 #1
2 2732
look up "rank"
"Willem-Jan Selen" <ws****@hotmail.com> wrote in message
news:1058827442.339033@cache2...
Is it possible so sort data from a table based on the count results?

I have the following

<% set rs = db.execute("Select * from tbleventinfo order by ename")
while not rs.EOF
tmp = rs("eid")
set rs1 = db.execute("Select count(eid) from tbleventdj where eid = " & tmp)
if rs1.EOF = false then
total = rs1.fields.item(0)
else
total = 0
end if
set rs1 = Nothing
echo rs("ename") & "(" & total & ")"

rs.moveNext
if rs.EOF = false then Response.write "<br>"
wend
set rs = Nothing
%>

which works fine. but as you can see it sorts it all out bases on the
ename...

Any help apriciated!!

Willem-Jan Selen

Jul 19 '05 #2
Thanx!! Works like a charm... and in one go aswell!

Willem-Jan Selen
"Chris Barber" <ch***@blue-canoe.co.uk.NOSPAM> wrote in message
news:uz**************@tk2msftngp13.phx.gbl...
One SQL statement should do it in one fell swoop:

SELECT tbleventinfo.ename as Name, Count(tbleventdj.eid) as CountOfEID
FROM tbleventinfo INNER JOIN tbleventdj
ON tbleventinfo.eid = tbleventdj.eid
GROUP BY tbleventinfo.ename
ORDER BY Count(tbleventdj.eid) DESC

Should get you:

Name CountOfEID

With CountOfEID decsending sort order (eg highest at top).

Untested so apologies for any typos.

Chris.
"Willem-Jan Selen" <ws****@hotmail.com> wrote in message
news:1058827442.339033@cache2...
Is it possible so sort data from a table based on the count results?

I have the following

<% set rs = db.execute("Select * from tbleventinfo order by ename")
while not rs.EOF
tmp = rs("eid")
set rs1 = db.execute("Select count(eid) from tbleventdj where eid =
" &
tmp)
if rs1.EOF = false then
total = rs1.fields.item(0)
else
total = 0
end if
set rs1 = Nothing
echo rs("ename") & "(" & total & ")"

rs.moveNext
if rs.EOF = false then Response.write "<br>"
wend
set rs = Nothing
%>

which works fine. but as you can see it sorts it all out bases on the
ename...

Any help apriciated!!

Willem-Jan Selen


Jul 19 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: P Adhia | last post by:
Hello, If the explain shows that DB2 needs to sort the result of a cursor, does that always happen? i.e. if the resultset of the cursor is empty, does the sort have any overhead? It appears...
1
by: Andrew Arace | last post by:
I scoured the groups for some hands on code to perform the menial task of exporting table data from an Access 2000 database to Oracle database (in this case, it was oracle 8i but i'm assuming this...
1
by: Gunjan Garg | last post by:
Hello All, I am working to create a generic datagrid which accepts a datasource(ListData - This is our own datatype) and depending on the calling program customizes itself for sorting,...
4
by: Joe | last post by:
Hello, I have a datagrid in an nested html table (one table inside of another table) and have set the allowsSorting property to true. I've created in the code-behind a method (Sub - I'm using...
21
by: yeti349 | last post by:
Hi, I'm using the following code to retrieve data from an xml file and populate a javascript array. The data is then displayed in html table form. I would like to then be able to sort by each...
1
by: Lyners | last post by:
I am trying to figure out the best way to do this (currently I am having a problem sorting). I have a vb.net program that contains 2 datagrids on a form for the end user. When the user is ready to...
6
by: max sharma | last post by:
Hi all, I am using a hashtable for my application. Its similar to word count application. How can I sort the hashtable w.r.t. the VALUE and not the KEY. The sample data of the table is given below...
2
by: joesindel | last post by:
So heres the deal... I work for a company in which numbers are dropping. The owners created a game where calling potential clients racks up points for crap like basketball ticekts and such. The...
1
by: rakeshnair | last post by:
i wrote a code in jsp to create dynamic table..the problem is i need data base connection when cursor moves from one cell to other... eg...when i enter product id in the first cell, the product name...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
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...
0
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,...

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.