Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
Author |
Topic |
ksemaska
Starting Member
1 Post |
Posted - 2013-04-23 : 13:29:13
|
Hello proffesionals! This what i got like 2 tables(1 is money income 2nd is money outcome) almost with same column names like id name user_id catalogue sum date(timestamp) This what i need:i need get data from both tables, then count SUM(sum) from both as one, but this is a bit hard because 2nd table sum values should be negative then SUM is counted. Also each SUM value should be counted for each day where we have any income,outcome (or just one of these) something like GROUP BY CAST(`data`AS DATE). Any ideas? Thanks for replies! :) |
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2013-04-23 : 13:43:08
|
[code]select dateadd(dd,datediff(dd,0,[date]),0), SUM([sum]) AS TotalFROM(SELECT *FROM table1UNION ALLSELECT *FROM table2)tGROUP BY dateadd(dd,datediff(dd,0,[date]),0)[/code]------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/https://www.facebook.com/VmBlogs |
 |
|
|
|
|