MidtermSQL (8) (1)
MidtermSQL (8) (1)
4) To change the value of a customer’s discount from 8 to 4, what command do we need to use:
a) INSERT b) SELECT c) REDUCE
d) ALTER TABLE e) UPDATE.
1
11) We used the DESCRIBE Customers; command to:
a) To display the data type of each column in your table is
b) Clean your database (get rid of all your tables)
c) To view the names of all your tables
12) The following commands defines, alter or remove the structure of a Table, but they do not add, modify
or remove rows from a table.
a) DDL b) DML c) Define Table Structure
13) The following commands add, modify or remove rows from a table. They do not define, alter or remove
the structure of a table
a) DDL b) DML c) modify
15) When we create a new database in MS-Access, we must start our database by first:
a) Creating Queries b) Creating Tables
c) Creating Forms d) Inserting Data into the Tables
16) We have two tables: Customers and Orders. We want that every time a user logs in, they can see the
name of the customer and the sum of the orders that a customer ordered without having to type in a
query. This can be done with the following command
a) A CREATE Temporary table b) CREATE NEW TABLE ON LOGIN
c) CREATE View d) ALTER TABLE
17) To view the names of all our tables in MySQL we use the command
a) View Tables b) Show Tables c) Show Databases d) Describe All
20) Which of the following actions can be done with the CREATE Command ?
a) Remove a table from a database b) Insert a new row into an existing table
c) Creates a new table d) Add a column or a Foreign Key to an existing table
e) Modify the value of a field f) Remove a row from a table
22) Which of the following statements generates the error ‘Ambiguous column name’:
a) SELECT dname, ename FROM Employees e, Departments d WHERE d.did=e.did;
b) SELECT did, d.dname FROM Employees e, Departments d;
Departments Employees
did dname bid ssn ename city salary did
d1 Marketing b1 s1 Sara Dubai 100000 d1
d2 Accounting b1 s2 Ahmed Al Ain 50000 d1
d3 Engineer b2 s3 Mohammed Dubai 100000 d2
s4 Hiroyuki Tokyo 75000 d3
Short Answer, write in SQL
25) List the name and the city of all employees SELECT ename, city FROM Employees;
26) List the Employees located in Dubai. SELECT * FROM Employees WHERE city = 'Dubai';
27) List the name of all Employees that have salary greater than 75000 SELECT ename FROM Employees
WHERE salary > 75000;
28) List the name of the employee that has the biggest salary SELECT ename FROM Employees
WHERE salary = (SELECT MAX(salary) FROM Employees);
29) List the name of the employees and their corresponding department name (result should contain 3 rows).
SELECT e.ename, d.dname
FROM Employees e
3
JOIN Departments d ON e.did = d.did;
30) List all possible combinations of the name of employees with the departments without relating the
employees to the departments (result should contain 6 rows).
SELECT e.ename, d.dname
FROM Employees e
CROSS JOIN Departments d;
31) List name of employees, name of their corresponding departments and name of their corresponding
branches.
SELECT e.ename, d.dname, b.bname
FROM Employees e
JOIN Departments d ON e.did = d.did
JOIN Branch b ON d.bid = b.bid;
32) List the department name and the sum of salary of all employees in the respective department.
SELECT d.dname, SUM(e.salary) AS total_salary
FROM Employees e
GROUP BY d.dname;
SELECT e.ename
FROM Employees e
WORLD CUP
4
Year Host Country Winner Runner Up MVP
1930 Uruguay Uruguay Argentina José Nasazzi
1934 Italy Italy Czechoslovakia Giuseppe Meazza
1938 France Italy Hungary Leônidas da Silva
1950 Brazil Uruguay Brazil Zizinho
1954 Switzerland West Germany Hungary Ferenc Puskás
1958 Sweeden Brazil Sweeden Didi
1962 Chile Brazil Czechoslovakia Garrincha
1966 England England West Germany Bobby Charlton
1970 Mexico Brazil Italy Pelé
1974 West Germany West Germany Holland Johan Cruyff
1978 Argentina Argentina Holland Mario Kempes
1982 Spain Italy Germany Paolo Rossi
1986 Mexico Argentina Germany Maradona
1990 Italy West Germany Argentina Salvatore Schillaci
1994 USA Brazil Italy Romário
1998 France France Brazil Ronaldo
2002 South Korea Brazil Germany Ronaldo
2006 Germany Italy France Zidane
2010 South Africa Spain Holland Diego Forlán
2014 Brazil Null Null Null
NATION
Country Continent
Brazil South America
Argentina South America
Uruguay South America
Italy Europe
Germany Europe
France Europe
England Europe
Spain Europe
34) Lists the name of the country that won the most ?
SELECT Winner, COUNT(*) AS Win_Count
FROM WorldCups
GROUP BY Winner
ORDER BY Win_Count DESC
LIMIT 1;
35) List the year and name of the host country that won when it hosted
5
SELECT Year, HostCountry
FROM WorldCups
WHERE HostCountry = Winner;
36) List the information of all world cups in ascending order by MVP name
SELECT *
FROM WorldCups
ORDER BY MVP ASC;
37) Lists the name of the continent and how many times that continent won (two tables).
SELECT N.Continent, COUNT(*) AS Win_Count
FROM WorldCups W
JOIN Nation N ON W.Winner = N.Country
GROUP BY N.Continent;