-2

これは私のMySQLテーブルです:

_______________________________________________
Id | Name| Employee id | Date       | Attendance
_______________________________________________
1  | xyz |     196     | 2013-04-01 | present  
2  | xyz |     196     | 2013-04-02 | present  
3  | xyz |     196     | 2013-04-03 | present  
4  | xyz |     196     | 2013-04-04 | absent  
5  | xyz |     196     | 2013-04-05 | present  
6  | abc |     197     | 2013-04-01 | present

7  | abc |     197     | 2013-04-02 | present  
8  | abc |     197     | 2013-04-03 | present  
9  | abc |     197     | 2013-04-04 | present  
10 | abc |     197     | 2013-04-05 | present

_______________________________________________

私は従業員がほとんど出席している日を数えたいと思っています.PHPで次のような結果が欲しいです:

___________________________________________________________
 Name| Employee id| Attendance     | Best OR NOT
___________________________________________________________
 xyz |  196       | 4 Present days |

 abc |  197       | 5 Present days | This is best employees of the year

__________________________________________________________________________

これどうやってするの?

4

5 に答える 5

0

このクエリを試してください..

SELECT *, COUNT(employee_id) AS cnt, CASE WHEN employee_id = (SELECT employee_id FROM employees
WHERE 1 GROUP BY  employee_id ORDER BY COUNT(employee_id) DESC LIMIT 0 , 1)   THEN 'Best' 
ELSE 'Not' END AS avl
FROM  `employees`
WHERE 1 
GROUP BY employee_id

必要に応じてテーブル名とフィールド名を変更します

于 2013-04-20T14:33:53.673 に答える
-1

これを試して。

   $query = mysql_query("select name ,`Employee id` as emplyee_id, CONCAT(count(`Employee id`),' Present days') as Attendance
   from Table1 
   where `Attendance` = 'present' group by `Employee id` ");



   while($row = mysql_fetch_array($query)) {
  echo $row['name']. " - " .$row['emplyee_id']. " - " .$row['Attendance']."</ br>";
 }

デモはこちら

于 2013-04-20T14:34:42.967 に答える