www.webdeveloper.com
Results 1 to 3 of 3

Thread: Counting quantities in a database

  1. #1
    Join Date
    Apr 2009
    Posts
    107

    Counting quantities in a database

    My company is hosting a sales promotion and all the data for each sale is kept in a mysql database. We want to see who the top salesperson is, by counting the number of sales of each participant, then post the one with the highest total.

    I am not even sure where to start with this using PHP and MySql. Can anybody help me get started.

  2. #2
    Join Date
    Nov 2008
    Posts
    2,477
    You will want to look into the SQL 'GROUP BY', 'ORDER BY' and 'LIMIT' statements. They will be what you need to select the top salesperson. Impossible to give any specific help without seeing some code or knowing your db structure though.
    The first rule of Tautology Club is the first rule of Tautology Club.

  3. #3
    Join Date
    Apr 2009
    Posts
    107
    Here is my table structure for the table:
    PHP Code:
    CREATE TABLE `orders` (
      `
    idint(11NOT NULL AUTO_INCREMENT,
      `
    po_numbervarchar(7) DEFAULT NULL,
      `
    productvarchar(55) DEFAULT NULL,
      `
    datetimestamp NULL DEFAULT CURRENT_TIMESTAMP,
      `
    shipping_firstnamevarchar(55) DEFAULT NULL,
      `
    shipping_lastnamevarchar(55) DEFAULT NULL,
      `
    shipping_companyvarchar(255) DEFAULT NULL,
      `
    shipping_address1varchar(255) DEFAULT NULL,
      `
    shipping_address2varchar(255) DEFAULT NULL,
      `
    shipping_cityvarchar(255) DEFAULT NULL,
      `
    shipping_statevarchar(255) DEFAULT NULL,
      `
    shipping_zipvarchar(255) DEFAULT NULL,
      `
    salespersonvarchar(55) DEFAULT NULL,
      `
    salesperson_idint(11) DEFAULT NULL,
      `
    distributorvarchar(255) DEFAULT NULL,
      `
    distributor_address1varchar(255) DEFAULT NULL,
      `
    distributor_address2varchar(255) DEFAULT NULL,
      `
    distributor_cityvarchar(255) DEFAULT NULL,
      `
    distributor_statevarchar(2) DEFAULT NULL,
      `
    distributor_zipint(11) DEFAULT NULL,
      `
    distributor_phonevarchar(15) DEFAULT NULL,
      `
    distributor_idint(11) DEFAULT NULL,
      `
    returnedint(11) DEFAULT NULL,
      `
    mra_numberint(11) DEFAULT NULL,
      
    PRIMARY KEY (`id`)
    ENGINE=MyISAM AUTO_INCREMENT=33 DEFAULT CHARSET=latin1 
    I have been reading up on 'Group By', 'Order by' and 'Limit' but would really appreciate an example to help we put it all together. Thanks in advance.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Posting Permissions

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



Recent Articles