Download as pdf or txt
Download as pdf or txt
You are on page 1of 12

Dhulikhel, Kavre

Department of Geomatics Engineering


Assignment

Spatial database management system


Submitted by: Cecil Ghimire, third year, Roll-10

Submitted to: Mr. Kushal Sharma


Initially two sql files were provided building.sql and rooms.sql that created two tables namely
buildings and rooms.

Columns of university table were:

● facilityke: A code for the type of facility. For instance ○ Buildings in the faculty of sciences are code T ○
Sports facilities are code D

● shortname: The building code, as used e.g. in room codes (e.g.all rooms in this building start with
code TI)

● longname: The full official name of the building

● bldgarea: The usable floor area of a building, in square meters

● floorcount: The number of floors in a building

● geom: The column that contains the shape (“geometry”) of the building

1. Find the long name of all buildings with facility code ’T’, ordered by area in descending order
(Result: 11 rows, beginning with “Mòdul Docent”)
2. Find the 3 buildings with the highest area (Result: 3 rows, codes HC, TD and JAA) .

3. Select all buildings with an area between 5000 and 6000 m2 , in descending order of area.
(Result: ITC, JC1, NA).
4. Select all buildings that contain “Facultat” in their long name. Hint: use the like operator.

Functions and aggregation

Aggregate functions are a special kind of functions that compute a “grand total” out of all rows in the
table.

The most important ones and ones that are implemented are:

● Count: Returns the total number of rows.

● Max: Returns the maximum value of a column

● Min: Returns the minimum value of a column

● Avg: Returns the average value of a column

● Sum: Returns the sum of all values in a column


1. What is the total number of rows in the buildings table? (Result: 44)

2. What is the number of facility types that appear in the table?

3.
4. What is the total number of buildings with facility type D?

5. What is the total area of all buildings (Result: 183307.94)

6. What is the average number of floors in all buildings? Round the number to the nearest integer. And
what if you only take into account buildings for which the number of floors is actually recorded (that
is, it is not 0)? Result: 3 and 4 respectively
Aggregation with grouping

1. Grouping divides the results of a query into logical groups, defined by the value of some common
attribute. For instance, the clause group by facilityke will divide all buildings into 14 logical groups,
one per facility type.
The following SQL was utilized

2. Modifying the previous query to include also the total area, and return the results ordered by total
area descending.
3. Find all facility types whose total area is greater than 25000 m2 .

4. (optional) For each interval of 5000 m2 (0-5000, 5000-10000, etc.), count the number of
buildings with an area in that interval. Hint: You can group by arbitrary arithmetic expressions;
For each interval they were done together by using subquery .
Subqueries:

Show the area of the 5 largest buildings as a percentage of the total area. Hint: Subqueries can
appear almost anywhere in a query, including the select clause.
Using subquery we perform task as follows:

2.6 Handling NULL values

1. Count the buildings whose long name is not known.


2. Show the name and area of all buildings of facility type D, displaying “Unnamed building” when
the name is not known. Order by area descending.

JOIN

A JOIN clause is used to combine rows from two or more tables, based on a related column
between them.

1. Change the previous query to select only rooms with a capacity greater than 100. Sort by building
area descending. (Should return 16 rows)
2. Show all classrooms in buildings with facility key 'J' and room capacity is between 50 and 70

3. What is the total room capacity of each building?


4. Show the number of rooms in all buildings with facility type 'J'. Result:

You might also like