Professional Web Applications Themes

Help Requested on "order by" - MySQL

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 CHT=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" ...

  1. #1

    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 CHT=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
    Lee Guest

  2. #2

    Default Re: Help Requested on "order by"

    On 29.05.2007 14:17, Lee Peedin wrote: 

    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
    Robert Guest

  3. #3

    Default Re: Help Requested on "order by"

    On Tue, 29 May 2007 14:57:09 +0200, Robert Klemme
    <com> wrote:
     
    >
    >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[/ref]

    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

    Lee Guest

  4. #4

    Default Re: Help Requested on "order by"

    On 29.05.2007 17:47, Lee Peedin wrote: 
    >> 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[/ref]
    >
    > 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?[/ref]

    That's *your* part of the homework.

    robert
    Robert Guest

Similar Threads

  1. "requested operation would cause one or more objects to be too small...."
    By chris_the_designer@adobeforums.com in forum Adobe Indesign Macintosh
    Replies: 3
    Last Post: August 26th, 11:12 PM
  2. "Cannot complete the requested operation" message.
    By Mark_Hatting@adobeforums.com in forum Adobe Illustrator Windows
    Replies: 14
    Last Post: November 3rd, 12:07 AM
  3. Replies: 6
    Last Post: December 15th, 04:17 PM
  4. Illustrator CS won't open-- error "Cannot Complete Requested Operation"
    By terjack@adobeforums.com in forum Adobe Illustrator Windows
    Replies: 9
    Last Post: June 22nd, 02:24 PM
  5. Replies: 0
    Last Post: July 10th, 03:43 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139