Received: from makus.postgresql.org (makus.postgresql.org [98.129.198.125]) by mail.postgresql.org (Postfix) with ESMTP id 3198C1DA4C1F for ; Tue, 17 Jan 2012 10:06:03 -0400 (AST) Received: from nm1-vm0.bullet.mail.sp2.yahoo.com ([98.139.91.202]) by makus.postgresql.org with smtp (Exim 4.72) (envelope-from ) id 1Rn9fi-0004Ch-Ty for pgsql-sql@postgresql.org; Tue, 17 Jan 2012 14:06:02 +0000 Received: from [98.139.91.64] by nm1.bullet.mail.sp2.yahoo.com with NNFMP; 17 Jan 2012 14:05:46 -0000 Received: from [98.139.91.57] by tm4.bullet.mail.sp2.yahoo.com with NNFMP; 17 Jan 2012 14:05:46 -0000 Received: from [127.0.0.1] by omp1057.mail.sp2.yahoo.com with NNFMP; 17 Jan 2012 14:05:45 -0000 X-Yahoo-Newman-Id: 998993.77277.bm@omp1057.mail.sp2.yahoo.com Received: (qmail 50162 invoked from network); 17 Jan 2012 14:05:45 -0000 DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=s1024; d=yahoo.com; h=DKIM-Signature:X-Yahoo-Newman-Property:X-YMail-OSG:X-Yahoo-SMTP:Received:References:In-Reply-To:Mime-Version:Content-Transfer-Encoding:Content-Type:Message-Id:Cc:X-Mailer:From:Subject:Date:To; b=11t5IdRRACgc6akkL210gyYg6o/Pcj5pGXSy2LSXblOKvGbyjx9akFIB4mMU/0zKq7IIV5r02216YY5s/USCFtiVNBmpR0eIu16f2bTy+XIdOis0A+EfQ9RVWF1oVRYCGH21/YbmXy0qru76pbjtablSOa8BKECyShZWshfiARY= ; DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s1024; t=1326809145; bh=cSkHYVZTHqfw12J9HrJi/tnSo+lq3Kfawng0rejZGX0=; h=X-Yahoo-Newman-Property:X-YMail-OSG:X-Yahoo-SMTP:Received:References:In-Reply-To:Mime-Version:Content-Transfer-Encoding:Content-Type:Message-Id:Cc:X-Mailer:From:Subject:Date:To; b=m8c8uUX7tXX2uIXSaxLteBAnttRr3FV/0xsc+uiz9Vw02YFwvquVpyACSjml0UMJhGs6HjGZwJRx1P2Cc3wHLTsrQqBQpwr1plCi1X/Wl/P3g5RZw5rR0DXt9c4c2uN4i2YI7xBSpWYcJNtR6QEFAUi63+bYUMxLHhIZMj7cgOo= X-Yahoo-Newman-Property: ymail-3 X-YMail-OSG: l4ydpSEVM1ly6Sih5Iu3t85MAbwFEW42OYYlgcT3biu7GRU 6BI4NMib0mxz6KcdjC2PqWB7QJ.tD1IIY_UNXTL8jyjQzjqHx0.B8gil8H0u 7rBUuUhvfp6mqMySu0jgHt76dHg1cg8zVKhvtai0YQ_SVtYSi6vX9dSwTW0s maVkUZoCK77R26Zh49pxfdbF0RHdtWvOPktYRbNX1B_BoOCUM_.2rU5gV2j3 XEYPJMxeg8Porni56th1740pPF1w4jvJuWnpLLlrojCmsFRv2eZubRVg1oVG KjMdWZlQOOOMr.zOy0VOhGvC97pO1t42UDx1ydDn54P6br8qhDN1RfxdG9v2 _o5XKZXNvXoiUGXzPNzx4qZgc4OqTUY7MAxUoRFSUYg1izVU.h83ytAf_gKF LXyzgd5N3LR6LIl20yqjiCJC83wDMGL48AFRPKrWf7pRkeg-- X-Yahoo-SMTP: mpGJl6eswBD2IBufoVEg0Pa8gg-- Received: from [192.12.17.102] (polobo@24.93.23.188 with xymcookie) by smtp103-mob.biz.mail.gq1.yahoo.com with SMTP; 17 Jan 2012 06:05:45 -0800 PST References: <-926980289640737999@unknownmsgid> <8682062e-b8fa-4778-a544-ab7671ff721b@c1g2000pbf.googlegroups.com> <20120117133519.GA29528@tux> In-Reply-To: <20120117133519.GA29528@tux> Mime-Version: 1.0 (1.0) Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=us-ascii Message-Id: Cc: "pgsql-sql@postgresql.org" X-Mailer: iPad Mail (9A405) From: David Johnston Subject: Re: sql query problem Date: Tue, 17 Jan 2012 09:05:44 -0500 To: Andreas Kretschmer X-Pg-Spam-Score: -1.9 (-) X-Archive-Number: 201201/74 X-Sequence-Number: 36245 On Jan 17, 2012, at 8:35, Andreas Kretschmer wro= te: > Alok Thakur wrote: >=20 >> Dear, >>=20 >> I am trying to provide you as much details as possible. >>=20 >> 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`) >> ) >>=20 >> 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`) >> ) >=20 > That's MySQL (i guess), please join a mysql-list. >=20 >=20 DB aside the query you are looking for is very simple SQL. The only real tr= ick is using SUM(case when status =3D 1/0 then 1 else 0 end=20 to obtain the proper counts. =20 Any reference materials covering table joining and group by will give you th= e syntax and examples needed to write your query. The lack of response is because most people are not going to bother answerin= g very simple queries that beginner reference materials cover adequately. P= lus, you didn't display any effort in attempting to solve the question yours= elf; you can do this by showing and and asking what you did wrong as opposed= to simply asking for an answer. David J.=