I'm definitely noob with SQL, I overloaded my head to write a complex query with the following table structure in Postgresql:
CREATE TABLE reports ( reportid character varying(20) NOT NULL, userid integer NOT NULL, reporttype character varying(40) NOT NULL, ) CREATE TABLE users ( userid serial NOT NULL, username character varying(20) NOT NULL, )
The purpose of the query is to get the number of report types for each user and display it in one column. There are three different types of reports.
A simple query with a group solution solves the problem, but displays it on different lines:
select count(*) as Amount, u.username, r.reporttype from reports r, users u where r.userid=u.userid group by u.username,r.reporttype order by u.username
source share