Purchase Solution

A detailed example of a SQL select statement using GROUP BY

Not what you're looking for?

Ask Custom Question

The schema of the DB is as follows:

Department(DeptNum, Descrip, Instname, DeptName, State, Postcode)
Academic(AcNum, *DeptNum, FamName, GiveName, Initials, Title)
Paper(PaNum, Title)
Author(*PaNum, *AcNum)
Field(FieldNum, ID, Title)
Interest(*FieldNum, *AcNum, Descrip)

Question 6:
Which fields have interests shared by academics from the same department? Output the field number, field ID and title, and the total number of academics who have interests.

I'm struggling with the conditions in the first part of the question.

Thanks Mick

Purchase this Solution

Solution Summary

This solution provides a detailed example of how to use the GROUP BY clause with a SQL SELECT statement.

Solution Preview

This key to this query is the GROUP BY clause that can be used with a SELECT statement. The GROUP BY clause instructs the DBMS to combine rows of data based on the columns that are specified in the GROUP BY clause.

Consider the query:

<pre>
SELECT * FROM interest
</pre>

This query will return all of the rows from the interest table. There are lots of rows with the same FieldNum value. If the GROUP BY clause is added then we only get one row per unique FieldNum.

<pre>
SELECT * FROM interest GROUP BY FieldNum
</pre>

The power of GROUP BY is in the fact that you can aggregate the combined rows. The SELECT can show the number of rows that have the same FieldNum:

<pre>
SELECT *, count(FieldNum) FROM ...

Purchase this Solution


Free BrainMass Quizzes
Basic Computer Terms

We use many basic terms like bit, pixel in our usual conversations about computers. Are we aware of what these mean? This little quiz is an attempt towards discovering that.

Basic Networking Questions

This quiz consists of some basic networking questions.

Inserting and deleting in a linked list

This quiz tests your understanding of how to insert and delete elements in a linked list. Understanding of the use of linked lists, and the related performance aspects, is an important fundamental skill of computer science data structures.

Word 2010: Table of Contents

Ever wondered where a Table of Contents in a Word document comes from? Maybe you need a refresher on the topic? This quiz will remind you of the keywords and options used when working with a T.O.C. in Word 2010.

Javscript Basics

Quiz on basics of javascript programming language.