我有一个表为用户记录活动:按类型/ contactid统计不同的消息
帐户ID /联系人ID /消息/时间/日期都被记录下来。 通常,该消息将是一个颜色,红色,绿色等..
任何帐户ID可以有多种的ContactID的
我想表明的是一样的东西:
AccountID Red Green Orange Account1 4 5 0 Account2 3 4 1 Account3 5 2 1
它基本上计数消息 我尝试了不同的人数为:
select
AccountID,
count(distinct message where message = 'RED'),
count(distinct message where message = 'Green'),
count(distinct message where message = 'Orange')
from
activities
where
date like '2013-01%';
但它返回一个错误1064,我不认为我的count(distinct....)
甚至接近有效,但我找不到任何例子,甚至我应该使用什么。任何帮助将是伟大的,谢谢。
你'date'列的数据类型是char/varchar? – bernie 2013-02-11 17:27:54