Professional Web Applications Themes

Point me to some references for Sorting - MySQL

TIA for you help, I have a query which works and sorts as expected. Now I need to do the same query, only this time I have two columns which need to be ysed and ordered by: The ysis is:(in php terms)(both columns are positive numbers) if (ColA=0) { // use Col B} elseif(ColA > 0 && colA < ColB) { // use Col A } else { //use ColB} The MsSQL manual doesn't seem to cover this, nor does the two beginner books I have. A pointer to a reference where I can learn about advanced "Order by" would ...

  1. #1

    Default Point me to some references for Sorting

    TIA for you help,
    I have a query which works and sorts as expected. Now I need to do the same
    query, only this time I have two columns which need to be ysed and
    ordered by:
    The ysis is:(in php terms)(both columns are positive numbers)

    if (ColA=0)
    { // use Col B}

    elseif(ColA > 0 && colA < ColB)
    { // use Col A
    }
    else
    { //use ColB}

    The MsSQL manual doesn't seem to cover this, nor does the two beginner
    books I have. A pointer to a reference where I can learn about advanced
    "Order by" would be great
    Thanks
    Marty


    Marty Meyers Guest

  2. #2

    Default Re: Point me to some references for Sorting

    "Marty Meyers" <martymexecpc.com> wrote in message
    news:1221g89ld0dtoabcorp.supernews.com...
    > if (ColA=0)
    > { // use Col B}
    >
    > elseif(ColA > 0 && colA < ColB)
    > { // use Col A
    > }
    > else
    > { //use ColB}
    SELECT ...
    ORDER BY CASE
    WHEN ColA = 0 THEN ColB
    WHEN ColA > 0 AND ColA < ColB THEN ColA
    ELSE ColB
    END

    It's based on the fact that the arguments to ORDER BY are expressions, not
    simply column names. You can use things like CASE and IF() to make
    interesting, complex expressions. Read more about these functions here:
    [url]http://dev.mysql.com/doc/refman/5.0/en/control-flow-functions.html[/url]
    > The MsSQL manual doesn't seem to cover this, nor does the two beginner
    > books I have. A pointer to a reference where I can learn about advanced
    > "Order by" would be great
    It's not much, but here's an article I found through Google:
    [url]http://www.sqlteam.com/item.asp?ItemID=2209[/url]
    It's written for Microsoft SQL Server users, but it mostly applies to MySQL
    as well.

    Regards,
    Bill K.


    Bill Karwin Guest

  3. #3

    Default Re: Point me to some references for Sorting

    Thanks Bill,
    That second article may just do the trick. I did solve the problem one way
    with a "Hammer". I added another column to the table, ran my query, did the
    PHP ysis, wrote the results back to the table and the re-queried with
    the new column. Works, but I'm not particularly proud of that solution.
    Marty


    "Bill Karwin" <billkarwin.com> wrote in message
    news:dvsr5k02je6enews2.newsguy.com...
    > "Marty Meyers" <martymexecpc.com> wrote in message
    > news:1221g89ld0dtoabcorp.supernews.com...
    > > if (ColA=0)
    > > { // use Col B}
    > >
    > > elseif(ColA > 0 && colA < ColB)
    > > { // use Col A
    > > }
    > > else
    > > { //use ColB}
    >
    > SELECT ...
    > ORDER BY CASE
    > WHEN ColA = 0 THEN ColB
    > WHEN ColA > 0 AND ColA < ColB THEN ColA
    > ELSE ColB
    > END
    >
    > It's based on the fact that the arguments to ORDER BY are expressions, not
    > simply column names. You can use things like CASE and IF() to make
    > interesting, complex expressions. Read more about these functions here:
    > [url]http://dev.mysql.com/doc/refman/5.0/en/control-flow-functions.html[/url]
    >
    > > The MsSQL manual doesn't seem to cover this, nor does the two beginner
    > > books I have. A pointer to a reference where I can learn about
    advanced
    > > "Order by" would be great
    >
    > It's not much, but here's an article I found through Google:
    > [url]http://www.sqlteam.com/item.asp?ItemID=2209[/url]
    > It's written for Microsoft SQL Server users, but it mostly applies to
    MySQL
    > as well.
    >
    > Regards,
    > Bill K.
    >
    >

    Marty Meyers Guest

Similar Threads

  1. Sorting array vs sorting paginated array
    By limitedwave777 in forum Macromedia Flex General Discussion
    Replies: 0
    Last Post: May 14th, 01:58 PM
  2. the angle from point A to point B (where the mouse is)
    By Jon Moyles in forum Macromedia Director 3D
    Replies: 3
    Last Post: February 24th, 04:03 AM
  3. Getting a camera to point at one point
    By mufc 1974 in forum Macromedia Director 3D
    Replies: 1
    Last Post: December 13th, 07:14 PM
  4. Add Point tool won't add point
    By Mike_Wickham@adobeforums.com in forum Adobe Illustrator Windows
    Replies: 4
    Last Post: June 6th, 12:17 AM
  5. The best way to rotate point around other point ?
    By Demonator webforumsuser@macromedia.com in forum Macromedia Director 3D
    Replies: 0
    Last Post: December 5th, 08:41 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