Sorting in SQL

Sorting in SQL

Post by Lars Marius Garsh » Fri, 24 Jan 1997 04:00:00



I have a problem with sorting on aggregate functions in Delphi, like this:

        SELECT Name, Count(ID)
        FROM tblTable
        ORDER BY ?!?!?

How do I order by Count(ID)?!?

Thanks,
--Lars M.

_______________________________________________________________________________

        Lars Marius Garshol

        "Life is a *ly transmitted disease", Andre Brink
        http://www.veryComputer.com/~larsga

 
 
 

Sorting in SQL

Post by pekka.haapalai.. » Fri, 24 Jan 1997 04:00:00




Quote:>I have a problem with sorting on aggregate functions in Delphi, like this:

>    SELECT Name, Count(ID)
>    FROM tblTable
>    ORDER BY ?!?!?

>How do I order by Count(ID)?!?

SELECT Name, COUNT(ID) as IDCount
FROM tblTable
GROUP BY Name
ORDER BY IDCount

Quote:>Thanks,

You're wellcome.

-----------------------
Pekka Haapalainen
e-mail: alpo<at>iki.fi
homepage: http://www.iki.fi/alpo/

 
 
 

Sorting in SQL

Post by pekka.haapalai.. » Sun, 26 Jan 1997 04:00:00


On Thu, 23 Jan 1997 20:48:10 -0500, Bernard Hamaoui


>Select Name, Count(ID) as CountID

It's not an ID for Count but it's the count of IDs ;->
So IDCount is perhaps better ;->

-----------------------
Pekka Haapalainen
e-mail: alpo<at>iki.fi
homepage: http://www.iki.fi/alpo/

 
 
 

Sorting in SQL

Post by J.Golovat » Tue, 28 Jan 1997 04:00:00




> > I have a problem with sorting on aggregate functions in Delphi, like this:

> >         SELECT Name, Count(ID)
> >         FROM tblTable
> >         ORDER BY ?!?!?

> > How do I order by Count(ID)?!?

> > Thanks,
> > --Lars M.

> Hi Lars,
> create view...(if it sql db) and select from it
> try:

> Select Name, Count(ID) as CountID
> from tblTable
> group by Name
> order by CountID

> Regards, Bernard (Montreal)

 
 
 

Sorting in SQL

Post by Esteban Astudil » Sun, 02 Feb 1997 04:00:00


|> >

|> > >
|> > > I have a problem with sorting on aggregate functions in Delphi, like this:
|> > >
|> > >         SELECT Name, Count(ID)
|> > >         FROM tblTable
|> > >         ORDER BY ?!?!?
|> > >
|> > > How do I order by Count(ID)?!?
|> > >
|> > > Thanks,
|> > > --Lars M.
|> >
|> > Hi Lars,
|> > create view...(if it sql db) and select from it
|> > try:
|> >
|> > Select Name, Count(ID) as CountID
|> > from tblTable
|> > group by Name
|> > order by CountID
|> >
|> > Regards, Bernard (Montreal)

 mejor..

 SELECT Name, COUNT(ID)
 FROM tblTable
 ORDER BY 2;

   Regards ,
 Esteban Astudillo V (Santiago de Chile)

--
 E S T E B A N >> (ESTE)
 ---------------------------+
 <http://www.dcc.uchile.cl> |  ... la vida ...                          |

 
 
 

1. Strange Sort Order - SQL vs Access

Hi,

I'm migrating an existing application from Jet based tables to SQL
Server 7.0.

I have run into a situation where I am getting unintuitive results from
the SQL Server 7.0 sort order.

The field in question is a varchar.

The field is part of an index and is used heavily for ordering data.
Occasionally,
the field will contain a Carriage Return / Line Feed combination.  The
tables
below compares the sort that I get from Access MDBs versus what I get
from SQL.

MSAccess
--------
A
AA
AA<cr><lf>A                  <cr><lf> is Carriage Return / Line Feed
AA A                               string contains a space
AAA

SQL Server 7.0
--------------
A
AA<cr><lf>A
AA
AA A
AAA

How do I get "AA<cr><lf>A" to sort after "AA", which to me makes more
sense.
Don't shorter strings always sort before longer strings, as is the case
in
both environments with "A", "AA", "AAA"?

I have tried using "rebuildm.exe" several times, in order to hopefully
get the
behavior that I want.

Any insight / suggestions will be GREATLY appreciated.

Thanks,

Bill

2. date conversion question

3. Sorting in SQL

4. Problem with rollback segment (ORA-01555)

5. ORACLE FORMS 4.5, how to use SORT in SQL query inside of When-Button-Pressed Trigger

6. Fine-Grained Access Control

7. Need help sorting with SQL

8. Importing from Oracle9i to Oracle8.0

9. sorting a SQL-recordset

10. Sorting in sql

11. Applying Pre-Sorts to SQL tables

12. Using pre-sorts on SQL tables