dbTalk Databases Forums  

Percentage per selected records, i.e. NOT by total records per table

comp.databases.postgresql comp.databases.postgresql


Discuss Percentage per selected records, i.e. NOT by total records per table in the comp.databases.postgresql forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
orofgggghtyy
 
Posts: n/a

Default Percentage per selected records, i.e. NOT by total records per table - 08-07-2009 , 02:09 PM






(Sorry, Couldn't find a pure SQL newsgroup)

This little request is working OK.
The idea is to get a percentage of the selected records based only on
the number of records per group
divided by
the number of selected records.
(i.e. NOT divided by the total number of records in the table.)
----------------------------
SELECT
locality,
count(*) as ctr,
count(*) * 100.00 /(SELECT count(*) from pat where locality like 'Pari%')
as percent
FROM Clients
WHERE locality like 'Pari%'
GROUP BY locality
ORDER BY percent desc
----------------------------
But ...
Is there another way of doing it that eliminates using of the where
locality like 'Pari%' clause, twice ?

TIA
Ororft

Reply With Quote
  #2  
Old   
Laurenz Albe
 
Posts: n/a

Default Re: Percentage per selected records, i.e. NOT by total records per table - 08-10-2009 , 02:57 AM






orofgggghtyy wrote:
Quote:
This little request is working OK.
The idea is to get a percentage of the selected records based only on
the number of records per group
divided by
the number of selected records.
(i.e. NOT divided by the total number of records in the table.)
----------------------------
SELECT
locality,
count(*) as ctr,
count(*) * 100.00 /(SELECT count(*) from pat where locality like 'Pari%') as percent
FROM Clients
WHERE locality like 'Pari%'
GROUP BY locality
ORDER BY percent desc
----------------------------
But ...
Is there another way of doing it that eliminates using of the where locality like 'Pari%' clause, twice ?
I can't think of a way.

Since the WHERE clause appears in two SELECT statements against two
different tables, I doubt that it can be done.

Is this a question about aesthetics or is there another problem
with the query as it is?

Yours,
Laurenz Albe

Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.