MYSQL

NAVIGATION
CATEGORIES
REFERRENCE
LINKS
  • Doing sum's if certain conditions are true

    0 answers - 960 bytes - related search similar search Add To My Delicious Add To My Stumble Upon Add To My Google Mark Add To My Facebook Add To My Digg Add To My Reddit

    [snip]
    ++
    | code | bin | min | ain |
    cin | dur |
    ++
    | NNE | 103939170759 | 485089817 | 3739.1827 |
    27797297 | 11681839027 |
    Now, what i need todo is exclude certain info from the above NNE entry
    if
    code2 is equal to something. So for example (in php terminology):
    if(code == 'NNE') {
    if(code2 == 'DENIED') { continue; }
    else {
    bin += bytes;
    if(bytes min) { min = bytes; }
    cin++;
    dur += dur;
    }
    }
    after that i could work out the average by dividing bin / cin for what
    in
    the report is called ain. Is there any way of achieving this via the sql
    query because the above is a hugely tedious way of doing it. I know
    mysql
    has an if() statement, but I have no idea how to implement it using what
    i
    want to achieve above.
    [/snip]
    Basically;
    SELECT SUM(IF(`code` = 'NNE', <calculation>, 0)) AS `ain` FRM `table`

Re: Doing sum's if certain conditions are true


max 4000 letters.
Your nickname that display:
In order to stop the spam: 2 + 1 =
QUESTION ON "MYSQL"

EMSDN.COM