SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Guru
    Join Date
    Nov 2004
    Location
    sweden
    Posts
    646
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)

    How to check the sum?

    I have a table with ticket sales.
    In one column the amount of tickets the customer order is listed.
    So, if one order 2 tickets that column will show 2, if someone order 8 tickets, that column is showing 8, a.s.o.

    Now I would like to just pick out the sum of all tickets sold so far.
    Don't know how to do that. What should I use? I guess there is something very simple to do this.

    The table is called showtickets
    The column is called tickets

  2. #2
    From Italy with love silver trophybronze trophy
    guido2004's Avatar
    Join Date
    Sep 2004
    Posts
    9,496
    Mentioned
    163 Post(s)
    Tagged
    4 Thread(s)

  3. #3
    SitePoint Member
    Join Date
    Mar 2008
    Posts
    19
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    select sum(tickets) as num from showtickets;

    or you can use group by to sum by date or user, fo \r example for all tickets sold today:
    :

    select sum(tickets) as num from showticket where today_field_name = CURDATE() group by today_field_name;
    Page Rank Checker Tools
    Search Expiring Domains with PR and Buy Domains with Page Rank

  4. #4
    SQL Consultant gold trophysilver trophybronze trophy
    r937's Avatar
    Join Date
    Jul 2002
    Location
    Toronto, Canada
    Posts
    39,251
    Mentioned
    59 Post(s)
    Tagged
    3 Thread(s)
    Quote Originally Posted by prtag View Post
    select sum(tickets) as num from showticket where today_field_name = CURDATE() group by today_field_name;
    an unfortunate example, because there's only going to be one value in the GROUP BY column, hence it's not required

    a better example would show the sum for each day in the last 7 days
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL
    "giving out my real stuffs"

  5. #5
    SitePoint Guru
    Join Date
    Nov 2004
    Location
    sweden
    Posts
    646
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    I really didn't get all this. How should I write that line to make it work?

  6. #6
    SQL Consultant gold trophysilver trophybronze trophy
    r937's Avatar
    Join Date
    Jul 2002
    Location
    Toronto, Canada
    Posts
    39,251
    Mentioned
    59 Post(s)
    Tagged
    3 Thread(s)
    Quote Originally Posted by brad62 View Post
    Now I would like to just pick out the sum of all tickets sold so far.
    Code:
    SELECT SUM(tickets) AS total
      FROM showtickets
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL
    "giving out my real stuffs"


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
  •