2

我有以下数据库

=================================
**id(PK)    orderid      email_content**
----------------------------------------------
1           6544        complain regarding service   
2           6544        request for replacement
3           6544        complain for late delievery
4           9822        thanking note
5           5762        faulty product
6           5762        complain for

我需要的是每个 orderid 的每个订单没有时间交互,例如 6544 order4 id 有多少时间电子邮件存在,我们有 3 个电子邮件..同样明智

orderid      no_of_iteraction
-------------------------------
6544         3
9822         1
5762         2

请建议适当的mysql查询

4

2 回答 2

1
SELECT count(id) as no_of_iterations, orderid from mytable group by orderid
于 2012-12-20T07:51:15.570 回答
-1

试试这个:

SELECT orderid, COUNT(orderid) no_of_iteraction
FROM tblTemp 
GROUP BY orderid

或者

根据您使用SUM函数的要求

SELECT orderid, SUM(1) no_of_iteraction
FROM tblTemp 
GROUP BY orderid

或者

SELECT orderid, SUM(cnt)
FROM (SELECT orderid, 1 cnt FROM tblTemp ORDER BY orderid) AS A 
GROUP BY orderid
于 2012-12-20T07:51:51.720 回答