Path: utzoo!attcan!uunet!mcvax!ukc!stc!datlog!ajs From: ajs@datlog.co.uk ( Andy Simms ) Newsgroups: comp.databases Subject: Re: INGRES oddity (or is it me?) Summary: INGRES shouldn't allow this Message-ID: <1682@dlvax2.datlog.co.uk> Date: 21 Dec 88 12:56:08 GMT References: <2183@nunki.usc.edu> Reply-To: ajs@datlog.co.uk ( Andy Simms ) Organization: Data Logic Ltd, Queens House, Greenhill Way, Harrow, London. Lines: 62 In article <2183@nunki.usc.edu> seligson@nunki.usc.edu (Richard Seligson) writes: >I am using the interactive SQL interface to Ingres Version 5.0/01. > >I want to create a relation of departments, classes, and the number of >students in each class. Based on that relation, I want to create a second >relation of departments and total number of students in its classes. > >When I create a table, and then a second table based on the first, I get >the correct results. However, when I create a view and then create a >second view based upon the first view, the second view contains incorrect data >(the first view is correct). > >I am wondering if it is incorrect to build a relation based on a view (Ingres >doesn't flag any error), or if I've done something wrong. > >create view v1 as >select dept.dname, class.classnum, students=count(enrollment.socsec) >from dept, enrollment, class >where class.dcode = dept.dcode >and enrollment.classnum = class.classnum >group by dept.dname, class.classnum; > >create view v2 as >select dname, tot_students=sum(students) >from v1 >group by dname; > Most SQLs disallow GROUP BY if the table referenced in the FROM clause is itself a "grouped view" (i.e. a view with a GROUP BY). To quote the ANSI standard (section 5.19 defining