GROUP BY Query - Got me f***ed

Results 1 to 2 of 2

Thread: GROUP BY Query - Got me f***ed

  1. #1
    Sean Malloy Guest

    Default GROUP BY Query - Got me f***ed

    I&#039m trying to group the results of a query from a table by Month and Year.. I can only group it by one or the other.. If I group by Month, I get press releases written a year (during the same month) before in the same row (counted anyways).. I don&#039t want to group by Year...<BR><BR><BR>Here is the table..<BR><BR>PressID ArtistID PressDate PressRelease<BR> 1 29 22/05/2000 Blah<BR> 2 29 19/05/2000 Blah<BR> 3 29 17/05/2000 Nothing Much<BR> 4 29 17/05/1999 hshshs<BR><BR>If I execute:<BR><BR>SELECT MAX(ArtistID) AS ArtistID, MAX(DATENAME(month, <BR> PressDate)) AS MonthName, MAX(DATENAME(year, <BR> PressDate)) AS Year, MAX(DATEPART(month, PressDate)) <BR> AS Month,<BR> (SELECT COUNT(*)<BR> FROM tblArtists_Press<BR> GROUP BY DATEPART(month, PressDate)) <BR> AS TotalRecords<BR>FROM tblArtists_Press<BR>GROUP BY DATEPART(month, PressDate)<BR><BR>against it, the results are: <BR><BR>ArtistID MonthName Year Month TotalRecords<BR> 29 May 2000 5 4<BR><BR>which is incorrect, because there is a press release in May 1999 as well.. <BR><BR>I need to somehow group by Year AND Month, not one or the other. Is there any way to do this without creating a stored procedure?<BR><BR>basically, I want the query to return this:<BR><BR>ArtistID MonthName Year Month TotalRecords<BR> 29 May 2000 5 3<BR> 29 May 1999 5 1<BR><BR>I don&#039t even know if its possible. Am I wasting my time?<BR>Regards,<BR><BR>Sean

  2. #2
    Sean Malloy Guest

    Default worked it out - ignore the thread


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts