Bluehost.com Web Hosting $6.95

Help Requested on "order by"

This is a discussion on Help Requested on "order by" within the MySQL Database forums, part of the Database Forums category; visit_totals CREATE TABLE `visit_totals` ( `uid` int(11) NOT NULL auto_increment, `edate` date NOT NULL, `enumber` int(11) NOT NULL, `ename` ...


Go Back   Usenet Forums > Database Forums > MySQL Database

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 05-29-2007
Lee Peedin
 
Posts: n/a
Default Help Requested on "order by"

visit_totals
CREATE TABLE `visit_totals` (
`uid` int(11) NOT NULL auto_increment,
`edate` date NOT NULL,
`enumber` int(11) NOT NULL,
`ename` varchar(40) NOT NULL,
`ehs` varchar(1) NOT NULL,
`eco` varchar(4) NOT NULL,
`enacode` int(4) NOT NULL,
`etraveltime` int(4) NOT NULL,
`epaidtime` int(4) NOT NULL,
`epaidmiles` int(4) NOT NULL,
PRIMARY KEY (`uid`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1

select eco,format((sum(epaidtime)/60),2) as pdtime
from visit_totals group by eco order by pdtime

"eco" "pdtime"
"0220" "106.83"
"0605" "108.77"
"0502" "108.90"
"0307" "117.38"
"0408" "135.05"
"0203" "140.32"
"0602" "147.72"
"0405" "149.78"
"0219" "156.50"
"0217" "168.75"
"0406" "172.17"
"0504" "180.12"
"0211" "191.62"
"0214" "198.78"
"0308" "209.67"
"0305" "209.75"
"0506" "21.10"
"0603" "212.15"
"0102" "212.98"
"0409" "224.17"
"0218" "238.40"
"0304" "248.32"
"0215" "254.03"
"0302" "260.40"
"0210" "266.30"
"0403" "278.15"
"0402" "298.18"
"0206" "301.58"
"0303" "345.92"
"0606" "42.22"
"0207" "526.50"
"0607" "54.73"
"0204" "542.78"
"0205" "597.37"
"0222" "64.00"
"0216" "68.60"
"0213" "69.32"
"0604" "71.62"
"0404" "85.07"
"0202" "870.07"
"0407" "94.92"
"0221" "97.13"
"0505" "98.58"
"0306" "99.37"

Note that the results appear to be sorted alphabetically. What can I
do to make the results be sorted numerically?

TIA
Lee P
Reply With Quote
  #2 (permalink)  
Old 05-29-2007
Robert Klemme
 
Posts: n/a
Default Re: Help Requested on "order by"

On 29.05.2007 14:17, Lee Peedin wrote:
> visit_totals
> CREATE TABLE `visit_totals` (
> `uid` int(11) NOT NULL auto_increment,
> `edate` date NOT NULL,
> `enumber` int(11) NOT NULL,
> `ename` varchar(40) NOT NULL,
> `ehs` varchar(1) NOT NULL,
> `eco` varchar(4) NOT NULL,
> `enacode` int(4) NOT NULL,
> `etraveltime` int(4) NOT NULL,
> `epaidtime` int(4) NOT NULL,
> `epaidmiles` int(4) NOT NULL,
> PRIMARY KEY (`uid`)
> ) ENGINE=InnoDB DEFAULT CHARSET=latin1
>
> select eco,format((sum(epaidtime)/60),2) as pdtime
> from visit_totals group by eco order by pdtime
>
> "eco" "pdtime"
> "0220" "106.83"
> "0605" "108.77"
> "0502" "108.90"
> "0307" "117.38"
> "0408" "135.05"
> "0203" "140.32"
> "0602" "147.72"
> "0405" "149.78"
> "0219" "156.50"
> "0217" "168.75"
> "0406" "172.17"
> "0504" "180.12"
> "0211" "191.62"
> "0214" "198.78"
> "0308" "209.67"
> "0305" "209.75"
> "0506" "21.10"
> "0603" "212.15"
> "0102" "212.98"
> "0409" "224.17"
> "0218" "238.40"
> "0304" "248.32"
> "0215" "254.03"
> "0302" "260.40"
> "0210" "266.30"
> "0403" "278.15"
> "0402" "298.18"
> "0206" "301.58"
> "0303" "345.92"
> "0606" "42.22"
> "0207" "526.50"
> "0607" "54.73"
> "0204" "542.78"
> "0205" "597.37"
> "0222" "64.00"
> "0216" "68.60"
> "0213" "69.32"
> "0604" "71.62"
> "0404" "85.07"
> "0202" "870.07"
> "0407" "94.92"
> "0221" "97.13"
> "0505" "98.58"
> "0306" "99.37"
>
> Note that the results appear to be sorted alphabetically. What can I
> do to make the results be sorted numerically?


If you want numeric ordering then do order by a numeric value, e.g.

select eco, format((sum(epaidtime)/60), 2) as pdtime
from visit_totals
group by eco
order by sum(epaidtime)

robert
Reply With Quote
  #3 (permalink)  
Old 05-29-2007
Lee Peedin
 
Posts: n/a
Default Re: Help Requested on "order by"

On Tue, 29 May 2007 14:57:09 +0200, Robert Klemme
<shortcutter@googlemail.com> wrote:

>On 29.05.2007 14:17, Lee Peedin wrote:
>>
>> select eco,format((sum(epaidtime)/60),2) as pdtime
>> from visit_totals group by eco order by pdtime
>>

>
>If you want numeric ordering then do order by a numeric value, e.g.
>
>select eco, format((sum(epaidtime)/60), 2) as pdtime
>from visit_totals
>group by eco
>order by sum(epaidtime)
>
> robert


Thanks Robert, but I guess my question now would be "Why isn't
format((sum(epaidtime)/60), 2) considered a numeric value when
sum(epaidtime) is?

Thanks again\
Lee

Reply With Quote
  #4 (permalink)  
Old 05-30-2007
Robert Klemme
 
Posts: n/a
Default Re: Help Requested on "order by"

On 29.05.2007 17:47, Lee Peedin wrote:
> On Tue, 29 May 2007 14:57:09 +0200, Robert Klemme
> <shortcutter@googlemail.com> wrote:
>
>> On 29.05.2007 14:17, Lee Peedin wrote:
>>> select eco,format((sum(epaidtime)/60),2) as pdtime
>>> from visit_totals group by eco order by pdtime
>>>

>> If you want numeric ordering then do order by a numeric value, e.g.
>>
>> select eco, format((sum(epaidtime)/60), 2) as pdtime
>>from visit_totals
>> group by eco
>> order by sum(epaidtime)
>>
>> robert

>
> Thanks Robert, but I guess my question now would be "Why isn't
> format((sum(epaidtime)/60), 2) considered a numeric value when
> sum(epaidtime) is?


That's *your* part of the homework.

robert
Reply With Quote
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT +1. The time now is 10:10 AM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0