Path: utzoo!attcan!uunet!midway!ncar!elroy.jpl.nasa.gov!usc!chaph.usc.edu!aludra.usc.edu From: ajayshah@aludra.usc.edu (Ajay Shah) Newsgroups: comp.databases Subject: Ease of SQL with an ugly schema Message-ID: <10698@chaph.usc.edu> Date: 9 Jul 90 09:07:27 GMT Sender: news@chaph.usc.edu Organization: University of Southern California, Los Angeles, CA Lines: 34 I'm pretty naive of databases and SQL, and wondered how this query would be represented using SQL: There is a table containing fields X Y and FLAG. FLAG takes values zero or one. One wishes to create the summation over the table of a variable Z where Z is defined as follows: If (flag = 0) then Z := X - Y else Z := X + Y So the query is essentially implemented by the algorithm: sum := 0; for (all records in table) do with current_record do begin If (flag = 0) then Z := X - Y else Z := X + Y sum := sum + Z end; writeln(sum); Representing this in SQL wasn't immediately obvious to me... can someone produce a demo? Thankx _______________________________________________________________________________ Ajay Shah, (213)747-9991, ajayshah@usc.edu The more things change, the more they stay insane. _______________________________________________________________________________