Re: sql query problem

From: David Johnston <polobo(at)yahoo(dot)com>
To: Andreas Kretschmer <akretschmer(at)spamfence(dot)net>
Cc: "pgsql-sql(at)postgresql(dot)org" <pgsql-sql(at)postgresql(dot)org>
Subject: Re: sql query problem
Date: 2012-01-17 14:05:44
Message-ID: F7F2A62D-C341-4B02-9529-E48FA38843A2@yahoo.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

On Jan 17, 2012, at 8:35, Andreas Kretschmer <akretschmer(at)spamfence(dot)net> wrote:

> Alok Thakur <alokthakur1987(at)gmail(dot)com> wrote:
>
>> Dear,
>>
>> I am trying to provide you as much details as possible.
>>
>> answer` (
>> `id` int(10) NOT NULL AUTO_INCREMENT,
>> `question_id` int(10) NOT NULL,
>> `user_id` int(10) NOT NULL,
>> `answer` int(10) NOT NULL, ->
>> `status` tinyint(1) NOT NULL, --> Status will be 0 or 1 means wrong
>> or right answer
>> `date` datetime NOT NULL,
>> PRIMARY KEY (`quiz_result_id`)
>> )
>>
>> user` (
>> `user_id` int(11) NOT NULL AUTO_INCREMENT,
>> `user` varchar(255) NOT NULL,
>> `username` varchar(255) NOT NULL,
>> `user_email` varchar(255) NOT NULL,
>> `user_gender` varchar(255) NOT NULL,
>> `refrence` varchar(255) NOT NULL,
>> `join_date` varchar(255) NOT NULL,
>> `status` tinyint(1) NOT NULL,
>> `banned` tinyint(1) NOT NULL,
>> PRIMARY KEY (`user_id`)
>> )
>
> That's MySQL (i guess), please join a mysql-list.
>
>

DB aside the query you are looking for is very simple SQL. The only real trick is using

SUM(case when status = 1/0 then 1 else 0 end

to obtain the proper counts.

Any reference materials covering table joining and group by will give you the syntax and examples needed to write your query.

The lack of response is because most people are not going to bother answering very simple queries that beginner reference materials cover adequately. Plus, you didn't display any effort in attempting to solve the question yourself; you can do this by showing and and asking what you did wrong as opposed to simply asking for an answer.

David J.

In response to

Browse pgsql-sql by date

  From Date Subject
Next Message Adrian Klaver 2012-01-17 15:19:47 Re: UPDATE COMPATIBILITY
Previous Message Andreas Kretschmer 2012-01-17 13:35:19 Re: sql query problem