0% found this document useful (0 votes)
59 views28 pages

Assighnment and Notes of Comp - Science

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

Assighnment and Notes of Comp - Science

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

CONTINUATION

Databases
STRUCTURED QUERY
LANGUAGE
ASSIGNMENT Page 309 Q15 – Q19
These questions use the following database table, WEATHER, that store weather readings.
15. Write the results returned by the following SQL script:
SELECT Temperature, Wind speed, Date
FROM WEATHER
WHERE Date = 11/12/2019 AND time < 15:00
16 . Write the results returned by the following SQL script:
SELECT Date, Time, Humidity
FROM WEATHER
WHERE Temperature > 20 AND Wind speed < 20
17. Write the results returned by the following SQL script:
SELECT Date, Time
FROM WEATHER
WHERE Temperature > 20 OR Wind speed >= 20
18. Complete the SQL script to display the time when the date is
12/12/2019 and the humidity is more than 50.
SELECT ......................................... .
FROM ......................................... .
WHERE ..................... = 12/12/2019 ............... Humidity > 50
19. Complete the SQL script to wind speed and temperature, when the wind
speed is either below 15 or above 20.
……………………………Wind speed, ........................................
FROM WEATHER
WHERE Wind speed .......... 15 ......... Wind speed ........ 2 0
ORDER BY
This command allows you to state which order the result will be
displayed in.
There are two options, ascending (ASC) and descending (DESC).
The default is ascending.
The order by statement comes after the
SELECT . . . FROM
or
SELECT . . . FROM . . . WHERE.
The following queries will use the following table, Orders:
Example 1
SELECT OrderID, Numberitems
FROM Orders
ORDER BY Numberitems ASC
This query will return:
Example 2
SELECT OrderID, TotalCost, Posted
FROM Orders WHERE Posted = Yes
ORDER BY TotalCost DESC
This query will return:
ASSIGNMENT Page 312 Q21 – Q24
These questions use the following database table,
WEATHER, that store weather readings.
20. Write the results returned by the following SQL script:
SELECT Temperature, Wind speed, Date
FROM WEATHER
ORDER BY Temperature
21. Write the results returned by the following SQL script:
SELECT Date, Time, Temperature
FROM WEATHER
ORDER BY Humidity DESC Humidity
22. Complete the SQL script to display the date, wind speed and humidity
in ascending order of wind speed.
…………………………….Date, Wind speed, Humidity
…………………………….WEATHER
…………………………….Wind speed
23. Complete the SQL script to display the date, time and temperature, in
descending order of humidity.
SELECT Date, Time, ......................................... .
FROM WEATHER
ORDER BY ......................................... .
24. Complete the SQL script to display the temperature, wind speed and
humidity in descending order of temperature.
………………… ……………… Wind speed, ……………………
FROM .........................................
………………………, ………………………….,
………………………
9.6 SUM
SUM command will add up the field that is written after it.
It is written in the select statement in the format:
SELECT SUM(field)
FROM table
- You can also use WHERE conditions. e.g.
SELECT SUM(field)
FROM table
WHERE condition
The following queries will use the following
table, Orders:
Example 1

SELECT SUM(Numberitems)
FROM Orders
This query will return: 52

It is calculated from adding together all of the


number of items (20 + 2 + 1 + 29)
Example 2
SELECT SUM(TotalCost)
FROM Orders
WHERE Posted = No
This query will return: 81.64
It is calculated from adding together all the
total costs where posted is No (21.99 +
59.65).
9.7 COUNT
This will count how many records meet the criteria,
or how many fields are in the table.
Count is in the format:
SELECT COUNT(field)
FROM table
The following queries will use the following table,
Orders:
Example 1

SELECT
COUNT(OrderID)
FROM table
The query will return: 4
Example 2

SELECT COUNT(NumberItems)
FROM table
WHERE Posted = Yes
The query will return: 2
Example 3

SELECT COUNT(OrderID)
FROM Orders
WHERE Numberitems > 10
The query will return: 2
ASSIGNMENT
These will use the following table, PRODUCTS:
1. What is the difference between SUM and COUNT?
2. What will be returned when the following SQL
script is run?
SELECT SUM(Quantity in stock)
FROM PRODUCTS
3. What will be returned when the following SQL script
is run?
SELECT COUNT(ID number)
FROM PRODUCTS
4. What will be returned when the following SQL
script is run?
SELECT SUM(Cost)
FROM PRODUCTS
WHERE Quantity in stock > 10
5. What will be returned when the following SQL
script is run?
SELECT COUNT(Name)
FROM PRODUCTS
WHERE Cost < 2.00
ASSIGNMENT Page 319 25 – Q 31
These questions use the following database table, ORDERS, that stores details about orders from a shop.
25. Write the results returned by the following SQL script:
SELECT SUM(Nurnberitems)
FROM ORDERS
26. Write the results returned by the following SQL script:
SELECT COUNT(Nurnberitems)
FROM ORDERS
27. Write the results returned by the following SQL script:
SELECT COUNT(Numberitems)
FROM ORDERS
WHERE Nurnberitems > 10
28. Write the results returned by the following SQL script:
SELECT SUM(TotalCost)
FROM ORDERS
WHERE FirstName = "Keanu"
29. Complete the SQL script to display how many orders James Smith has made.
SELECT .......................................... (FirstName)
FROM ORDERS
WHERE FirstName = "James" ............. LastName = "Smith"
30. Complete the SQL script to calculate the total cost of orders where 5 or more
items have been ordered.
SELECT .......................................... (TotalCost)
FROM ORDERS
………………………….NumberItems…………………….5
31. Complete the SQL script to calculate how
many orders cost more than 50.00
SELECT ...................... (Nurnberitems)
FROM .........................................
WHERE ......................................... .
END
NEXT TOPIC
TOPIC 7: ALGORITHM
AND PROBLEM
SOLVING

You might also like