mysql - Adding a summed field to a select query -


assuming have query:

select * table left join table_b on <conditions> <conditions> 

and want add summed column it, this:

select *, sum(table.field) table left join table_b on <conditions> <conditions> 

can done?

*the second query returns single row expected, need them all. , if can done in same query, prefer it.

as far know can't return aggregation , source data in single query. can run sub-query this:

select *, sum_query.sum_field table join (select sum(field) sum_field table) sum_query 

this still 2 queries, mysql joining results you. think code readability suffer if you're doing things this.


Comments

Popular posts from this blog

css - I want to align grid in center -

python - SWIG function not printing output -

Contact Form PHP Email Script -