Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1Y8e8M-00071k-G0 for pgsql-sql@arkaria.postgresql.org; Wed, 07 Jan 2015 00:05:58 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.80) (envelope-from ) id 1Y8e8L-0002tm-Of for pgsql-sql@arkaria.postgresql.org; Wed, 07 Jan 2015 00:05:57 +0000 Received: from makus.postgresql.org ([2001:4800:1501:1::229]) by malur.postgresql.org with esmtps (TLS1.2:DHE_RSA_AES_256_CBC_SHA256:256) (Exim 4.80) (envelope-from ) id 1Y8e8L-0002tg-1q for pgsql-sql@postgresql.org; Wed, 07 Jan 2015 00:05:57 +0000 Received: from mwork.nabble.com ([162.253.133.43]) by makus.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1Y8e8H-0008M0-LN for pgsql-sql@postgresql.org; Wed, 07 Jan 2015 00:05:55 +0000 Received: from msam.nabble.com (unknown [162.253.133.85]) by mwork.nabble.com (Postfix) with ESMTP id AD65DFB8139 for ; Tue, 6 Jan 2015 16:05:52 -0800 (PST) Date: Tue, 6 Jan 2015 17:05:52 -0700 (MST) From: sqlnewbie2015 To: pgsql-sql@postgresql.org Message-ID: <1420589152496-5833121.post@n5.nabble.com> Subject: Count values that match elements in csv string MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Pg-Spam-Score: 1.6 (+) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-sql Precedence: bulk Sender: pgsql-sql-owner@postgresql.org Hello All- I am having difficulty limiting my query to only count items which match any part of a csv string table. My current query runs but it seems to only count one of the elements listed in the csv and stops rather then count all the activities that match with the csv. select (sum (kept)/60) from (select distinct sa.staff_id, sa.service_date, sa.client_id, sa.actual_duration as kept from rpt_scheduled_activities as sa inner join rpt_staff_performance_target as spt on sa.staff_id = spt.staff_id where (sa.status = 'Kept' and sa.service_date between '01-nov-2014' and '30-nov-2014' and sa.activity_name in (select regexp_split_to_table(spt.activity,',') from rpt_staff_performance_target as spt)) ) as p Details: I need to calculate how many hours our staff spends seeing clients. Each staff has different appointments that can count toward this. The specified appointments for each staff are listed as comma separated values. My existing query calculates the appointment hours for each staff in a given time period. However, I need help limiting my query to only include specified activities for each staff. My current where clause uses IN to compare the appointment (i.e. activity) listed in the staff's schedule with what is listed an an approved appointment type (i.e. performance target activity). Thank you for your consideration and for any tips you can provide! Cara -- View this message in context: http://postgresql.nabble.com/Count-values-that-match-elements-in-csv-string-tp5833121.html Sent from the PostgreSQL - sql mailing list archive at Nabble.com. -- Sent via pgsql-sql mailing list (pgsql-sql@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-sql