Jump to content


Top Ten style search

  • Please log in to reply
1 reply to this topic

#1 MeanMrMustard

  • New Members
  • Pip
  • Newbie
  • 5 posts

Posted 05 June 2006 - 01:47 AM

I have a DB where the results of a incentive program are kept.

Each employee who receives a merit goes into this DB. Can someone help me write a query that produces a ranking from the DB. Every Merit produces another entry in the DB so I can count the number of instances f any one employee while in a loop but can seem to create a ranking style output.

Any help would be appreciated.

#2 Barand

  • Moderators
  • Sen . ( ile || sei )
  • 18,021 posts

Posted 05 June 2006 - 02:06 PM

I'm guessing you have a structure similar to this

employee             merit
---------            ----------
emp_id    ----+      id
emp_name      |      award_date
              +---<  emp_id

$sql = "SELECT e.emp_name, COUNT(*) AS merits
        FROM employee e INNER JOIN merit m
        ON e.emp_id = m.emp_id
        GROUP BY e.emp_name
        ORDER BY merits DESC";

If you are still using mysql_ functions, STOP! Use mysqli_ or PDO. The longer you leave it the more you will have to rewrite.

Donations gratefully received


|baaGrid| easy data tables - and more
|baaChart| easy line, column and pie charts

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users