Solved

Getting top 50 transaction for each customer and getting transaction count no

Posted on 2010-11-09
2
706 Views
Last Modified: 2012-05-10
Hi,

I am writing a query in Mysql. I need top 50 transaction for each customer done by customer (ORDER BY TRANSACTION.TRANSACTIONDATE)

Also, can I get the transaction count no for each transaction. I mean first transaction placed should have count 1, next one should have count 2 etc

I need to bring this information in my select query.

I am getting all of these transaction details in bulk by excel file and admin can upload excel file as many times as they wanted,
so Its hard to take column 'count' in transaction table.

Please suggest me to bring this information in select query by using function or anything else

Thanks & Regards
SELECT 

	TRANSATION.CLIENTID, TRANSACTION.PRODUCTISINCODE, TRANSACTION.TRANSACTIONDATE,TRANSATION.ISAPPROVED

FROM 

	TRANSACION

WHERE 

	TRANSACTION.ISDELETED=0

GROUP BY 

	TRANSATION.CLIENTID

ORDER BY 

	TRANSACTION.TRANSACTIONDATE

Open in new window

0
Comment
Question by:tia_kamakshi
2 Comments
 
LVL 58

Accepted Solution

by:
cyberkiwi earned 500 total points
ID: 34099095

SELECT CLIENTID, PRODUCTISINCODE, TRANSACTIONDATE, ISAPPROVED

FROM

(

SELECT 

	T.CLIENTID, T.PRODUCTISINCODE, T.TRANSACTIONDATE, T.ISAPPROVED,

	@r:=case when @c=T.CLIENTID then @r+1 else 1 end r,

	@c:=T.CLIENTID

FROM 

   (select @c:=null,@r:=0) n, TRANSACTION T

WHERE 

	T.ISDELETED=0

ORDER BY 

	T.CLIENTID, T.TRANSACTIONDATE

) X

WHERE r<=50

ORDER BY

	CLIENTID, TRANSACTIONDATE

Open in new window

0
 

Author Closing Comment

by:tia_kamakshi
ID: 34103138
Great

Many Thanks
0

Featured Post

Zoho SalesIQ

Hassle-free live chat software re-imagined for business growth. 2 users, always free.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Get error when search query run in loop 3 44
Mysql not caching queries 4 64
phpMyAdmin simple sql statement 3 52
how to get total ticket count on days wise using mysql 24 54
Foreword In the years since this article was written, numerous hacking attacks have targeted password-protected web sites.  The storage of client passwords has become a subject of much discussion, some of it useful and some of it misguided.  Of cou…
Foreword This is an old article.  Instead of using the MySQL extension that was used in the original code examples, please choose one of the currently supported database extensions instead.  More information is available here: MySQLi / PDO (http://…
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).

895 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now