Professional Web Applications Themes

Selecting max sum of 2 colums - MySQL

i have a table like: | id | number1 | number2| |1 |12 | 1 | |2 |1 | 12 | |3 |199 | 0 | ---------------------------- I want to : 1) select the highest sum of number1 and number2. 2) select row with highest number1 3) select row with highest number2 4) select bigger difference of number1 and number2 I know it might be easy but i am new to MySQL. Thanks... Best regards, Nicos...

  1. #1

    Default Selecting max sum of 2 colums

    i have a table like:

    | id | number1 | number2|
    |1 |12 | 1 |
    |2 |1 | 12 |
    |3 |199 | 0 |
    ----------------------------

    I want to :
    1) select the highest sum of number1 and number2.
    2) select row with highest number1
    3) select row with highest number2
    4) select bigger difference of number1 and number2

    I know it might be easy but i am new to MySQL. Thanks...

    Best regards,
    Nicos

    Nicos Guest

  2. #2

    Default Re: Selecting max sum of 2 colums


    Nicos wrote: 

    Well the first one could be like this:
    SELECT id, number1, number2, (`number1` + `number2`) AS sum
    FROM numbers
    ORDER BY sum DESC
    LIMIT 1

    strawberry Guest

  3. #3

    Default Re: Selecting max sum of 2 colums


    Nicos wrote: 
    There are a few ambiguities in your request that it would be useful to
    clear up:
    1) Do you want all these in a single query or are they 4 separate
    goals?
    2) If all in a single query: if say 1 and 2 coincide, do you want the
    row listed twice or only once?
    3) when you say "bigger difference of number1 and number2", I assume
    you mean "biggest", but is this the absolute value or does it matter
    whether number1 is bigger than number2 or vice versa?

    Captain Guest

  4. #4

    Default Re: Selecting max sum of 2 colums


    Captain Paralytic wrote: 
    > There are a few ambiguities in your request that it would be useful to
    > clear up:
    > 1) Do you want all these in a single query or are they 4 separate
    > goals?
    > 2) If all in a single query: if say 1 and 2 coincide, do you want the
    > row listed twice or only once?
    > 3) when you say "bigger difference of number1 and number2", I assume
    > you mean "biggest", but is this the absolute value or does it matter
    > whether number1 is bigger than number2 or vice versa?[/ref]

    Yes, sorry i didn't clear this up earlier. All are 4 seperated goals
    When i say bigger difference i meant (number2-number1) , but i sorted
    this out with LIMIT :)

    Nicos Guest

  5. #5

    Default Re: Selecting max sum of 2 colums


    Nicos wrote: 
    SELECT id, (number1+number2) as sum ORDER BY sum DESC LIMIT 1 
    SELECT id, number1 ORDER BY number1 DESC LIMIT 1 
    SELECT id, number2 ORDER BY number2 DESC LIMIT 1 
    SELECT id, (number2 - number1) as diff ORDER BY diff DESC LIMIT1
     

    Nicos Guest

  6. #6

    Default Re: Selecting max sum of 2 colums


    strawberry wrote: 
    >
    > Well the first one could be like this:
    > SELECT id, number1, number2, (`number1` + `number2`) AS sum
    > FROM numbers
    > ORDER BY sum DESC
    > LIMIT 1[/ref]

    What's a guy got to do to get five stars then? ;-)

    strawberry Guest

  7. #7

    Default load 38000 images into MYSQL...



    Hello strawberry...

    I have a problem.......I want to load 38000 images into MYSQL...How can
    I do that???can u help me.....actually..i have to create a database for
    the employee for my company..I have to load all the images according to
    their ID number....Can I do that in MYSQL becoz before this I have
    tried it in access..but access only limited to 2GB data only....The
    size for the images are about 5 GB. So now I want to do it in
    MYSQL.....Plz help me.......

    leen Guest

Similar Threads

  1. php records across 2 colums
    By eddo32 in forum Dreamweaver AppDev
    Replies: 3
    Last Post: April 25th, 03:16 PM
  2. radio button in colums are not grouped correctly
    By George Paiva in forum ASP.NET Data Grid Control
    Replies: 4
    Last Post: January 17th, 04:38 AM
  3. Trying to make 4 equal colums?
    By innerdream webforumsuser@macromedia.com in forum Macromedia Flash Sitedesign
    Replies: 0
    Last Post: January 7th, 06:32 AM
  4. [PHP] dynamical balancing text in two colums
    By SLanger@spirit21.de in forum PHP Development
    Replies: 1
    Last Post: September 3rd, 09:37 AM
  5. dynamical balancing text in two colums
    By Dynamical.Biz in forum PHP Development
    Replies: 2
    Last Post: August 27th, 01:05 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