🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.vdbase.data.sql
Article #67

Percentage calculation with sql in one pass

#67
From: Klaas Wolters
Date: Thu, 08 Apr 1999 00:00
31 lines
1137 bytes
Hello

I have the following table Patient

Id Type


How can I calculate the percentage of  # patients grouped by type with one
SQL statement. ( LOCAL SQL)

I already tried this

Select Type, Count(P1.Id)/Count(p2.Id) *100 as Percentage
From
  Patient p1,
  Patient p2
Where p1.Id = p2.Id
Group by Type

But te second count gives the same results as the first count . when
removing the Where clause the calculation is correct. but takes a lot of
time because the second count is done every selected row.

I want to use this in a decision grid so the user can select between # or
percentage.

Any suggestions.

Thanks in advance

Klaas Wolters
Technical Details
Message-ID: <7ei7k7$1i612@forums.borland.com>
Path: arc1-ca.pugleaf.net!unknown!not-for-mail

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: ff5a1,8f161b4a65d9c69a,start
X-Google-Attributes: gidff5a1,public
From: "Klaas Wolters" <triple.eye@tip.nl>
Subject: Percentage calculation with sql in one pass
Date: 1999/04/08
Message-ID: <7ei7k7$1i612@forums.borland.com>
X-Deja-AN: 464012760
Organization: Another Netscape Collabra Server User
X-MimeOLE: Produced By Microsoft MimeOLE V4.72.3110.3
Newsgroups: borland.public.vdbase.data.sql