2

i have following database

=================================
**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

what i need is no of time interaaction per order that is for each orderid , how many time email is present for example for 6544 order4 id we have 3 emails..and like wise

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

please suggest appropriate mysql query

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 に答える