Results 1 to 4 of 4
  1. #1
    Join Date
    Aug 2003

    New to mysql, am I being too ambitious?!


    I've just started learning MySql. It's great, but I'm finding some bits a little tricky!

    Could someone please tell me how to do the following? I've come across it in quite a few scripts I've (attempted!) to make, but I always end up trying to create a lengthy work-around.

    As an example, I've got a table with 3 columns and 5 records:

    EDIT: I can't work out how to add lots of spaces in the 'table' below, I hope you understand what I'm getting at!

    column 1 column 2 column 3
    1 4 3
    2 4 3
    1 5 2
    5 4 3
    1 2 5

    All I'd like to do is add up every record present in column 1.
    (1 + 2 + 1 + 5 + 1)

    Is it as hard as I'm making out? Any help is greatly appreciated!

    Thank you.

  2. #2
    Join Date
    Mar 2004
    select sum(<column 1>) as totals from <table>

    Just adjust to that the column name and table name and you're set.

  3. #3
    Join Date
    Jan 2003
    As unlucky said, sum() is the one you want, but you should check out some of the other 'grouping functions' for other useful tools.
    Game Servers are the next hot market!
    Slim margins, heavy support, fickle customers, and moronic suppliers!
    Start your own today!

  4. #4
    Join Date
    Aug 2003
    Thank you both for your replies.

    I had no idea it was so easy, it's certainly a more effective way than the loops I'd been using.

    I've been looking at the grouping functions as you suggested hiryuu. I've already found a few replacements so thanks a lot for that.

    Thank you both again.

Posting Permissions

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