Solved

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

Posted on 2010-11-09
2
710 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

VMware Disaster Recovery and Data Protection

In this expert guide, you’ll learn about the components of a Modern Data Center. You will use cases for the value-added capabilities of Veeam®, including combining backup and replication for VMware disaster recovery and using replication for data center migration.

Question has a verified solution.

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

Introduction In this article, I will by showing a nice little trick for MySQL similar to that of my previous EE Article for SQLite (http://www.sqlite.org/), A SQLite Tidbit: Quick Numbers Table Generation (http://www.experts-exchange.com/A_3570.htm…
Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

809 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