I have a union all query in a stored procedure.
WHat I would like to do is Sum a column and return that query to the client
How would I do this?
Malcolm
Here is the query to count on the union query. mysql> select count(*) as UnionCount from -> ( -> select distinct UserId from union_Table1 -> union -> select distinct UserId from union_Table2 -> )tbl1; The following is the output displaying the count.
If you need to add a group of numbers in your table you can use the SUM function in SQL. This is the basic syntax: SELECT SUM(column_name) FROM table_name; If you need to arrange the data into groups, then you can use the GROUP BY clause.
SELECT othercol1, othercol2, SUM(bar) FROM ( SELECT othercol1, othercol2, bar FROM RT UNION ALL SELECT othercol1, othercol2, bar FROM FM ) foo GROUP BY othercol1, othercol2
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With