It's UWAweek 47

help1402

This forum is provided to promote discussion amongst students enrolled in CITS1402 Relational Database Management Systems.

Please consider offering answers and suggestions to help other students! And if you fix a problem by following a suggestion here, it would be great if other interested students could see a short "Great, fixed it!"  followup message.

How do I ask a good question?
Displaying selected article
Showing 1 of 684 articles.
Currently 104 other people reading this forum.


 UWA week 35 (2nd semester, week 6) ↓
SVG not supported

Login to reply

👍?
helpful
3:34pm Wed 28th Aug, Adam W.

Hi, This has also been updated, there is an issue with the way the conditions in the having are evaluated. HAVING count(cust_id) > 2 AND city OR phone IS NOT NULL should be HAVING COUNT(cust_id) > 2 AND (city IS NOT NULL OR phone IS NOT NULL) You need to have the criteria attached to both of the boolean checks (for city and for phone). It could be that sqlite lets you do this, by evaluating the 'city' as true automatically, then it would be 'TRUE OR phone IS NOT NULL' which would automatically mean its always going to be TRUE. Thanks, Adam. ANONYMOUS wrote:
> Hello, > > > Worksheet number 2 has a question that goes as follows: > > Q) Display credit code, and the count of publishers in a column called Number of > publishers. Then group according to the creditcode for all the cases where either the > count is greater than 2 or the city or phone is not empty. Then apply ascending order. > > Solution: > > SELECT creditcode, count(cust_id) AS 'Number of Publishers' > FROM publishers > GROUP BY creditcode > HAVING count(cust_id) > 2 and city OR phone IS NOT NULL > ORDER BY creditcode ASC; > > > My query is that: > > 1) In the HAVING clause, shouldn't the answer by "OR city OR phone IS NOT NULL"? Why is it and when the question explicitly states "either or" > > 2) Can we have an alternative solution that goes like this, using the where clause: > > select creditcode, count(cust_id) as "number of publishers" > from publishers > where city or phone is NOT NULL > group by creditcode > having count(cust_id)>2 > order by count(cust_id) desc; > > Would this be incorrect? If so then why? > > Thanks

The University of Western Australia

Computer Science and Software Engineering

CRICOS Code: 00126G
Written by [email protected]
Powered by history
Feedback always welcome - it makes our software better!
Last modified  8:08AM Aug 25 2024
Privacy policy