Q&A about the site for researchers and developers who explore the principles of a system through analysis of its structure, function, and operation
SELECT VoteTypes.Id, VoteTypes.Name, p.Count, p.First, p.Last, p.HasUserId, p.ExactDate FROM VoteTypes LEFT JOIN ( SELECT VoteTypeId, COUNT(*) AS Count, MIN(CreationDate) AS First, MAX(CreationDate) AS Last, COUNT(UserId) AS HasUserId, COUNT( CASE WHEN CreationDate <> DATEFROMPARTS( YEAR(CreationDate), MONTH(CreationDate), DAY(CreationDate)) THEN 1 END) AS ExactDate FROM Votes GROUP BY VoteTypeId ) p ON VoteTypes.Id = p.VoteTypeId ORDER BY VoteTypes.Id