I have a database with many records from members that each member creates posts for themselves. I want to show daily, weekly, monthly and yearly created posts for each user. What is the best and most effective way to do this? best query and optimize code. Use caching system? What data structure should I use? My Database is SQL Server and code behind is C#
GROUPING SETS
SELECT YEAR(PostDate) AS PostYear, MONTH(PostDate) AS PostMonth, DAY(PostDate) As PostDay, COUNT(1) As NumberOfPosts FROM UserPosts WHERE UserID = @UserID GROUP BY GROUPING SETS ( YEAR(PostDate), (YEAR(PostDate), MONTH(PostDate)), (YEAR(PostDate), MONTH(PostDate), DAY(PostDate)) ) ;
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)