0% found this document useful (0 votes)
52 views2 pages

16085126D - Tse Justin Chung Heng - DB - Assignment

This document contains the responses of a student named Tse Justin Chung Heng to various questions about SQL queries. The student provided the SQL code to select unique identifiers from tables, count records by team IDs, sum scores from a records table, and join tables to find the number of games played by each team. The responses demonstrate knowledge of writing basic to intermediate SQL queries to analyze data from multiple tables.

Uploaded by

Justin
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
52 views2 pages

16085126D - Tse Justin Chung Heng - DB - Assignment

This document contains the responses of a student named Tse Justin Chung Heng to various questions about SQL queries. The student provided the SQL code to select unique identifiers from tables, count records by team IDs, sum scores from a records table, and join tables to find the number of games played by each team. The responses demonstrate knowledge of writing basic to intermediate SQL queries to analyze data from multiple tables.

Uploaded by

Justin
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

Name: Tse Justin Chung Heng

Student ID: 16085126D


Question 1

Question 2
(a) TEAMID, because this attribute is unique in table TEAM.
(b)
CREATE TABLE TEAM
( TEAMID INTEGER NOT NULL UNIGUE,
TEAMNAME VARCHAR(50),
PRIMARY KEY (TEAMID)
);
(c) MATCHDATE ,HOME and AWAY, because only this combination of attribute will be unique
in the table RECORD.
(d)
SELECT COUNT(*) AS TOTALHOMEGAME
FROM RECORD
WHERE (HOME=8);
(e)
SELECT COUNT(*) AS TOTALGAME
FROM RECORD
WHERE (HOME=4) or (AWAY=4);
(f)
SELECT (SUM(HOMESCORE) +SUM(AWAYSCORE)) AS TOTALSCORE
FROM REOCRD
(g)
SELECT COUNT(*) AS TOTALGAME
FROM RECORD R, TEAM T
WHERE (T.TEAMID=R.HOME or T.TEAMID=R.AWAY) and T.TEAMNAME=’Eagles’
(h)
SELECT TEAMID, TEAMNAME, COUNT(*) AS TOTALGAME
FROM TEAM, RECORD
WHERE (TEAM.TEAMID= RECORD.HOME) or (TEAM.TEAMID= RECORD.AWAY)
GROUP BY TEAM.TEAMID, TEAM.TEAMNAME
(i)
Field: TEAMID TEAMID TEAMNAME HOMESCORE
Table: TEAM TEAM TEAM RECORD
Total: WHERE GROUP BY GROUP BY SUM
Sort: DESCENDING
Show: ˅ ˅ ˅
Criteria: RECORD.HOME
Or:

You might also like