计算给定值的行外观

时间:2014-02-18 17:35:55

标签: mysql count

我有一个名为private_message的表格,其中包含以下字段:senderreceiver

我想知道特定发件人有多少次向某个人发送邮件,例如:

**Name**     **Times**
David        5
Michael      2
John         1

1 个答案:

答案 0 :(得分:1)

试试这个:

SELECT 
  sender as 'From',
  receiver as 'To',
  count(receiver) as 'Times'
FROM private_message
GROUP BY sender, receiver

结果可能类似于:

From         To         Times
David        Emil           5
Michael      Møller         2
John         Ringgaard      1
Emil         Ravinder       1