mysql - distinct created_by and sum total_amount for each created_by -


i stuck this.

i have 2 tables in db (mysql) 1 (i_mst) , 2 (o_mst)

i have date column in i_mst , amount column in o_mst , created_by column in o_mst.

what need

distinct created_by , sum each created_by amount i_mst date       between '2013-01-01'     , '2013-08-01' 

and return in single row.

to trying this.

select distinct ( o_mst.created_by ), o_mst.amount o_mst left join i_mst on i_mst.i_date i_date between '2013-01-01' , '2013-08-01' order `o_mst`.`amount` desc limit 0 , 5 

it gives me multiple created_by ids , amount.

i want distinct created_by rows , sum total_amount each created_by row.

help me if possible.

thanks

try this

select o_mst.created_by, sum(o_mst.amount) o_mst inner join i_mst on i_mst.inq_mst_id = o_mst.inq_mst_id  i_date between '2013-01-01' , '2013-08-01' group o_mst.created_by desc limit 0 , 5 

Comments

Popular posts from this blog

php - Calling a template part from a post -

Firefox SVG shape not printing when it has stroke -

How to mention the localhost in android -