| Re: Help Requested on "order by" -
06-04-2007, 07:58 AM
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 |