How Can Relational Algebra Be Used to Find Diseases With Only One Medication?

  • Context: Undergrad 
  • Thread starter Thread starter Shaitan00
  • Start date Start date
  • Tags Tags
    Algebra
Click For Summary

Discussion Overview

The discussion focuses on how to formulate a relational algebra statement to identify diseases that have only one corresponding medication, based on a provided table structure. The scope includes theoretical aspects of relational algebra and its application in querying databases.

Discussion Character

  • Technical explanation
  • Debate/contested
  • Mathematical reasoning

Main Points Raised

  • One participant describes the structure of the TREATMENT table and provides an example to illustrate the problem of identifying diseases with only one medication.
  • Another participant suggests looking into "aggregate functions" as a potential solution, referencing an external resource.
  • A different participant expresses difficulty in using aggregate functions to filter results, specifically seeking a method to list diseases with a count of one.
  • One participant explains the role of the HAVING keyword in SQL, noting its purpose in filtering results after aggregation, contrasting it with the WHERE clause.

Areas of Agreement / Disagreement

The discussion reveals uncertainty regarding the application of aggregate functions in relational algebra, with no consensus on how to effectively filter results to meet the query requirements.

Contextual Notes

Participants mention the need for aggregation and filtering but do not resolve the specifics of how to implement these concepts in relational algebra. There is a lack of clarity on the exact syntax and operations required.

Shaitan00
Messages
13
Reaction score
0
I am trying to write the RELATIONAL ALGEBRA statement for a query defined as follows:
"Find the diseases for which there is only one medication"

I have a table TREATMENT with two attributes, DISEASE & MEDICATION
TREATMENT (disease, medication)

This table holds a list of diseases and corresponding medication, of course for each diseases that can potentially be multiple medications, and for some only one. For example assume you have something that resembles the following:

Disease | Medication
--------------------
FLU | med1
FLU | med2
CANCER | med3
HIV | med4
FLU | med5

In this case you would expect to get CANCER & HIV (as they only have 1 corresponding medication) whereas FLU would be excluded because it has 3... (etc...)

Any help would be greatly appreciated...
Thanks,
 
Last edited:
Mathematics news on Phys.org
I was looking at that already - but couldn't figure it out...
WIth those expressions I can easily determine the COUNT for each but how do I list only the diseases that have a count = 1?

Thanks,
 
SQL uses a HAVING keyword for such cases, which is nothing but a select operation on the result of the aggregation. I believe the only reason to define in SQL a different keyword than WHERE was to distinguish between a select operation after the aggregation (HAVING), as opposed to before (WHERE).
 

Similar threads

Replies
20
Views
18K
  • · Replies 7 ·
Replies
7
Views
1K
  • · Replies 1 ·
Replies
1
Views
1K
  • · Replies 1 ·
Replies
1
Views
11K
  • · Replies 5 ·
Replies
5
Views
1K
  • · Replies 33 ·
2
Replies
33
Views
3K
  • · Replies 32 ·
2
Replies
32
Views
8K
Replies
2
Views
3K
Replies
3
Views
2K
  • · Replies 146 ·
5
Replies
146
Views
12K