r***@gmail.com
2013-09-05 03:50:05 UTC
Hello,
Below is a table called Projects:
RowID User DateCreated Proj Hours
1 Dan 2013-06-21 100A 6
2 Dan 2013-06-22 100A 3
3 Dan 2013-06-25 300A 1
4 Dan 2013-06-26 300A 7
5 Joe 2013-06-22 500A 5
6 Joe 2013-06-23 500A 5
7 Joe 2013-06-27 600A 10
This query produces the below output:
SELECT [User], right(convert(varchar, DateCreated, 106), 8) as 'Month', [Proj], SUM(HOURS) AS [Hours],
100.0 * SUM(Hours) / SUM(SUM(Hours)) OVER (Partition BY User, right(convert(varchar, DateCreated, 106), 8)) AS [%]
FROM Projects
GROUP BY User, right(convert(varchar, DateCreated, 106), 8), Proj
GO
User Month Proj Hours %
Dan Jun 2012 100A 9 53
Dan Jun 2012 300A 8 47
Joe Jun 2012 500A 10 50
Joe Jun 2012 600A 10 50
How do I make the output look like this?
User Month
Dan Jun 2012 100A 9 53% 300A 8 47%
Joe Jun 2012 500A 10 50% 600A 10 50%
Below is a table called Projects:
RowID User DateCreated Proj Hours
1 Dan 2013-06-21 100A 6
2 Dan 2013-06-22 100A 3
3 Dan 2013-06-25 300A 1
4 Dan 2013-06-26 300A 7
5 Joe 2013-06-22 500A 5
6 Joe 2013-06-23 500A 5
7 Joe 2013-06-27 600A 10
This query produces the below output:
SELECT [User], right(convert(varchar, DateCreated, 106), 8) as 'Month', [Proj], SUM(HOURS) AS [Hours],
100.0 * SUM(Hours) / SUM(SUM(Hours)) OVER (Partition BY User, right(convert(varchar, DateCreated, 106), 8)) AS [%]
FROM Projects
GROUP BY User, right(convert(varchar, DateCreated, 106), 8), Proj
GO
User Month Proj Hours %
Dan Jun 2012 100A 9 53
Dan Jun 2012 300A 8 47
Joe Jun 2012 500A 10 50
Joe Jun 2012 600A 10 50
How do I make the output look like this?
User Month
Dan Jun 2012 100A 9 53% 300A 8 47%
Joe Jun 2012 500A 10 50% 600A 10 50%