I'm using SQL-Server 2005.
I have two tables Users and Payments which has a foreign key to Users. Both Users and Payments have a date column (Users set their value during registration and Payments gets a value during payment). Users has a column called isPaymentsRecurring as bit which tells me to renew the user or not. The value is 1 on default = recurring. Payments has a column called paymentSum as tinyint where I insert the value of payment. ( first payment is equal to recurring one)
I need to get a few statistics about that for simple line chart, grouped by date. To separate single days I use the hack below to get whole day as a single item.
Day hack
dateadd(dd,datediff(dd,0,date),0)
What I need to get are the values below all must be grouped by day hack.
1.Unique users in system per day
2.Users that ordered once and then set isPaymentRecurring to 0.
3.Sum of paymentSum per day
4.How many users got recurring payment per day. This means orders of user per day except first order in system.
Thanks, I have queries that work but they don't work as I want them to thus I want pros opinion on that.