Professional Documents
Culture Documents
IFB105 Week 8 Tutorial Worksheet Solutions
IFB105 Week 8 Tutorial Worksheet Solutions
QUERY RESULT-SET
SELECT (1 + 1 + 1); 3
SELECT 9 * 10 AS NINETY; 90
Now, instead of querying the database for all the columns in the table, try writing a query that will retrieve the
address, location and capacity of the bicycle racks. A partial of the query has been supplied below.
Now, write a query that will select the description and service type for all ferry terminals. You will need to select
your data from a different table. Type your query below once you have tested it.
1
Task 5: Selecting Distinct Data
Using the DISTINCT clause will indicate to MySQL to only return unique values in a column. For example, the
following query will return a list of suburbs that the traffic counters were used in. Execute the query answer the
questions below.
Write a query to find pontoons with a length of 65 metres. List the description, suburb, serviceType and
pontoonLength
Write a query to generate a unique list of suburbs with pontoon lengths greater than 20 metres.
This query lists the description, service type, whether a seat is present and the number of boarding gates IF there
is a seat present AND there are more than two boarding gates OR if there is a seat present AND there is one
boarding gate.
2
Write a query to answer the following question.
Produce a list containing the address, location and capacity of Brisbane bike racks where the capacity of the
rack is either 4, 6, 10 or 20. You must only use logical operators (and, or).
This query lists the address, capacity and type of bicycle rack, only if the bicycle rack is a wheel rack or toaster
rack.
This query lists the description, suburb and length of a pontoon if the pontoon is between 10 and 20 metres
long.
3
Write a query to answer the following question.
Produce a list of traffic counters that were placed in a suburb containing ‘oo’. List the suburb, counterLocation
and speedLimit.
SELECT suburb,counterLocation, speedLimit
FROM loganTrafficCounters
WHERE suburb LIKE ‘%oo%’;
Task 9: Order By
Execute the following query and describe the result set.
This query lists the counter location, suburb and the roads’ speed limit for automatic traffic counters, ordered by
speed limit in ascending order.
This query lists the counterLocation, speedLimit and averageSpeed of traffic counters that were placed on roads
with a speed limit between 50 and 60. The list is sorted by speed limit ascending, then by averageSpeed
ascending.
4
Task 10: Bringing it all together (challenge!)
Write a query to answer the following question.
List the streetName, suburb, averageSpeed and speedLimit for traffic counters that recorded an average speed
that is 10km/h greater than the speedLimit. Hint: you can perform mathematical operations as a condition
(example: WHERE (a - b) > 5).