Saravana Nadar
Saravana Nadar

Reputation: 1

How can i find out order wise topper in this month using mysql

name     amount  date
----------------------------------------------------
sarava   10000     2015-12-01
muthu    5000     2016-01-08
sarava   7000     2016-01-06
muthu    10000    2016-01-16

expected output height order taken on this month: name->muthu
amount->15000

Upvotes: 0

Views: 46

Answers (2)

AnkiiG
AnkiiG

Reputation: 3488

Try as below :

SELECT name, SUM( amount ),date_format( `date` , '%M' ) as month
FROM tablename
where month='January'
GROUP BY date_format( `created_at` , '%M' ) 

Upvotes: 1

Arion
Arion

Reputation: 31239

It sounds like you want to sum the amount by name. Maybe you want something like this:

SELECT SUM(amount) AS amount, name from table1 GROUP BY name;  

Upvotes: 0

Related Questions