Article View: borland.public.interbase.sql
Article #906Re: Sum of rows
From: Wayne Niddery [TeamB]
Date: Sun, 15 Apr 2007 16:15
Date: Sun, 15 Apr 2007 16:15
36 lines
2482 bytes
2482 bytes
aleplgr wrote:
> Hi! I have a table of patients who executed a test, each test has 10
> items and I have to generate a new column with the sum of 3 of those
> 10 items. The original table columns are this: PatientID Date Items
> Points Tester.
> Date is the date the test took place, a test is started and finished
> at the same date
> Items are the 10 items of the test, one in each row of the table
> Tester is the doctor that applied the test to the patient.
> Points is the score that the patient got in that item, that date,
> applied by that tester.
> A tester can apply the same test to the same patient the same day
> more than once.
> Two different testers can apply the same test to the same patient
> the same date so that date one patient will have 2 scores for each
> item.
>
> I need to create a table with this columns:
> PatientID Date Tester SumPoints
> (where SumPoints is the sum of 3 known items of the test, for example
> Item1, Item2 and Item3)
If I understand your description correctly then this should be workable in a
single SQL statement.
select PatientID, Date, Tester, Sum(Points) as SumPoints
from table
where Items in ('itemA', 'itemB', 'itemC')
group by PatientID, Date, Tester
--
Wayne Niddery - Winwright, Inc (www.winwright.ca)
"If there is any principle of the Constitution that more imperatively
calls for attachment than any other, it is the principle of free
thought � not free thought for those who agree with us, but freedom for
the thought that we hate." - Oliver Wendell Holmes
Technical Details
Message-ID:
<46224fa6@newsgroups.borland.com>Path:
arc1-ca.pugleaf.net!g2news1.google.com!news2.google.com!news.glorb.com!solnet.ch!solnet.ch!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mailReferences:
<4621e830$1@newsgroups.borland.com>Show Full Headers
Complete Article Headers
X-Google-Thread: 114a0e,f48a4e6400e7b013 X-Google-Attributes: gid114a0e,public X-Google-Language: ENGLISH,ASCII Reply-To: "Wayne Niddery [TeamB]" <wniddery@chaffaci.on.ca> From: "Wayne Niddery [TeamB]" <wniddery@chaffaci.on.ca> Newsgroups: borland.public.interbase.sql References: <4621e830$1@newsgroups.borland.com> Subject: Re: Sum of rows Date: Sun, 15 Apr 2007 12:15:32 -0400 Lines: 38 X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2900.3028 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.3028 X-RFC2646: Format=Flowed; Original NNTP-Posting-Host: 69.17.170.228 Message-ID: <46224fa6@newsgroups.borland.com> X-Trace: newsgroups.borland.com 1176653734 69.17.170.228 (15 Apr 2007 09:15:34 -0800) Path: arc1-ca.pugleaf.net!g2news1.google.com!news2.google.com!news.glorb.com!solnet.ch!solnet.ch!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail