Q&A for Drupal developers and administrators
declare @UserId int = ##UserId##; with vote_results as ( select votetypeid, count(*) as "number of votes" from posts inner join votes on posts.id = votes.postid where posts.owneruserid = @Userid group by votetypeid ) select * from vote_results inner join votetypes on vote_results.votetypeid = votetypes.id order by id