1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

How to query numbers ?

Discussion in 'Databases' started by Amilo, Jan 24, 2007.

  1. #1
    I have a list of numbers in a database,one number per column,seven numbers per row.

    I want to be able to add up how many numbers match from the row below in each row as in my example.

    43 18 33 12 48 22 25
    17 43 6 29 11 1 8 =1
    34 35 49 6 2 21 46 =2
    41 30 48 38 45 35 46 =1
    30 23 47 26 39 2 31 =3
    15 24 20 47 2 31 29
    31 43 25 18 29 3 23
    38 26 27 13 43 41 35 =1
    39 42 40 32 26 25 41


    Another query question if I may:

    I have 2 fields

    Day of week , Weather

    How do I do a query such as:
    when did it last rain ?
    How many times was it cloudy ?

    Monday sunny
    Tuesday cloudy
    Wednesday cloudy
    Thursday overcast
    Friday rain
    Saurday cloudy
    Sunday sunny
     
    Amilo, Jan 24, 2007 IP
  2. picouli

    picouli Peon

    Messages:
    760
    Likes Received:
    89
    Best Answers:
    0
    Trophy Points:
    0
    #2
    :eek: Maybe it's just me, but can you explain this better?!? Thanks!

    (I suppose day_of_week is a date field)

    SELECT day_of_week FROM weathers_table WHERE weather = 'rain' ORDER BY day_of_week DESC LIMIT 0,1
    Code (markup):
    (I suppose you have one record per day)

    SELECT COUNT(*) FROM weather_table WHERE weather = 'cloudy' GROUP BY weather
    Code (markup):
    HTH, cheers! :)
     
    picouli, Jan 24, 2007 IP
  3. maiahost

    maiahost Guest

    Messages:
    664
    Likes Received:
    35
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Not just you - I saw this earlier but decided it was me that didn't get the point.
     
    maiahost, Jan 24, 2007 IP
  4. Amilo

    Amilo Peon

    Messages:
    624
    Likes Received:
    18
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Sorry guys Its my fault, I am not the best at trying to explain this stuff.

    I have a list of 6 temperature numbers in a row each day.

    The following day I have another 6 numbers.

    I want to query the database to see how many of the 6 numbers were the same as the day before.
     
    Amilo, Jan 24, 2007 IP
  5. picouli

    picouli Peon

    Messages:
    760
    Likes Received:
    89
    Best Answers:
    0
    Trophy Points:
    0
    #5
    Uhm... I think your DB is not designed very well, you should have one row for each temperature for each day (not 6 temperatures in a record)
    Otherwise it's quite a PITA to do what you ask for - at least for me, and using SQL only...
     
    picouli, Jan 26, 2007 IP
  6. kashem

    kashem Banned

    Messages:
    1,250
    Likes Received:
    76
    Best Answers:
    0
    Trophy Points:
    0
    #6
    Hi
    If you dont have any problem , it will be easier to understand and help if you post the table structure here.

    Just a qustion 6 numbers in a row means are they all on separate fields or in the same fields?
     
    kashem, Jan 26, 2007 IP
  7. Amilo

    Amilo Peon

    Messages:
    624
    Likes Received:
    18
    Best Answers:
    0
    Trophy Points:
    0
    #7
    Thanks Kashem,yes they are in 6 seperate fields.

    Each row is id date day then the 6 temperature fields (9 fields in total).
     
    Amilo, Jan 26, 2007 IP