SQL Assignment
James Byerly
BUSI 201 – 005
November 16, 2022
Most of the actions you need to perform on a database are done with SQL statements.
1. The following SQL statement selects all the records in the "Customers" table:
2. The following SQL statement selects the "CustomerName" and "City" columns from the
"Customers" table:
3. The following SQL statement selects all (including the duplicates) values from the
"Country" column in the "Customers" table:
SQL
Statement:
select
Count(*)
as
DistinctCountries
from
(Select
Distinct
Country
from
Customers);
James
Byerly
sec
@5
11/16/22
Edit
the
SQL
Statement,
and
click
"Run
SQL"
to
see
the
result.
Run
SQL
»
Result:
Number
of
Records:
1
DistinctCountries
21
SQL
Statement:
Select
Count(Distinct
Country)
from
Customers;
James
Byerly
sec
@5
11/16/22
Edit
the
SQL
Statement,
and
click
"Run
SQL"
to
see
the
result.
Result:
Number
of
Records:
1
Count(Distinct
Country)
21
4. The following SQL statement selects all the customers from the country "Mexico", in the
"Customers" table:
5. The following SQL statement selects all fields from "Customers" where country is
"Germany" AND city is "Berlin":
SQL
Statement:
Select
*
from
Customers
Where
Country='Germany'
and
City='Berlin';
James
Byerly
sec
@5
11/16/22
Edit
the
SQL
Statement,
and
click
"Run
SQL"
to
see
the
result.
Run
SQL
»
Result:
Number
of
Records:
1
CustomerID
CustomerName
ContactName
1
Alfreds
Futterkiste
Maria
Anders
SQL
Statement:
Select
*
from
Customers
Where
City="Berlin'
or
City='Miinchen’
;
James
Byerly
sec
@5
11/16/22
Edit
the
SQL
Statement,
and
click
"Run
SQL"
to
see
the
result.
Run
SQL
»
Result:
Number
of
Records:
2
CustomerID
CustomerName
ContactName
1
Alfreds
Futterkiste
Maria
Anders
25
Frankenversand
Peter
Franken
48°F
sunny
Address
Obere
Str.
57
Address
Obere
Str.
57
Berliner
Platz
43
Qserh
gp
OO
@ |
City
PostalCode Country
Berlin
12209
Germany
City
PostalCode
Country
Berlin
12209
Germany
Munchen
80805
Germany
Pmun:e¢a
SQL
Statement:
Select
*
from
Customers
Where
Country='Germany’
or
Country='Spain';
James
Byerly
sec
@5
11/16/22
Edit
the
SQL
Statement,
and
click
"Run
SQL"
to
see the
result.
Run
SQL
»
Result:
Number
of
Records:
16
CustomerID
CustomerName
ContactName
Address
City
1
Alfreds
Futterkiste
Maria
Anders
Obere
Str.
57
Berlin
6
Blauer
See
Delikatessen
Hanna Moos
Forsterstr.
57
Mannheim
8
Bélido
Comidas
preparadas
Martin
Sommer
C/
Araquil,
67
Madrid
17
Drachenblut
Delikatessend
Sven
Ottlieb
Walserweg
21
Aachen
22
FISSA
Fabrica
Inter.
Salchichas
S.A.
Diego
Roel
C/
Moralzarzal,
86
Madrid
25
Frankenversand
Peter
Franken
Berliner
Platz
43
Minchen
29
Galeria
del
gastrénomo
Eduardo
Saavedra
Rambla
de
Catalufia,
23
Barcelona
48°F
Sunny
SQL
Statement:
Select
*
from
Customers
Where
not
Country='Germany'
;
James
Byerly
sec
@5
11/16/22
Edit
the
SQL
Statement,
and
click
"Run
SQL"
to
see
the
result.
Ue)
ie
Result:
Number
of
Records:
80
CustomerID
CustomerName
ContactName
Address
City
2
Ana
Trujillo
Emparedados
y
Ana
Trujillo
Avda.
de
la
Constitucién
2222
México
D.F.
helados
3
Antonio
Moreno
Taqueria
Antonio
Moreno
Mataderos
2312
México
D.F.
4
Around
the
Horn
Thomas
Hardy
120
Hanover
Sq.
London
5
Berglunds
snabbkép
Christina
Berglund
__Berquvsvagen
8
Luled
48°F
sunny
aes
bp
OOeC@RSE
SHE.
PostalCode
12209
68306
28023
52066
28034
80805
08022
PostalCode
05021
05023
an
gp
ODeC@LBSHE:
Oa
WA1
1DP
S-958
22
Country
Germany
Germany
Spain
Germany
Spain
Germany
Spain
Country
Mexico
Mexico
UK
Sweden
6. The following SQL statement selects all customers from the "Customers" table, sorted by
the "Country" column:
ye
SQL
Statement:
Select
*
from
Customers
Order
by
Country
desc;
James
Byerly
sec
@5
11/16/22
Edit
the
SQL
Statement,
and
click
"Run
SQL"
to
see
the
result.
Run
SQL»
Result:
Number
of
Records:
91
CustomerID
CustomerName
33
35
46
47
Arr
Temps
drop
GROSELLA-Restaurante
HILARION-Abastos
LILA-Supermercado
LINO-Delicateses
SQL
Statement:
Select
*
from
Customers
Order
by
Country,
CustomerName;
James
Byerly
sec
@5
11/16/22
ContactName
Address
City
PostalCode
Manuel
Pereira
54
Ave,
Los
Palos
Grandes
Caracas
1081
Carlos
Hernandez
Carrera
22
con
Ave. Carlos
Soublette
#8-35
San
Cristobal
5022
Carlos
Gonzalez
Carrera
52
con
Ave.
Bolivar
#65-98
Llano
Barquisimeto
3508
Largo
Felipe
Izquierdo
Ave.
5
de
Mayo
Porlamar
I.
de
4980
an
bp
OOeCuUBSHE:
ova
Edit
the
SQL
Statement,
and
click
"Run
SQL"
to
see the
result.
Uriel
ies
Result:
Number
of
Records:
91
CustomerID
CustomerName
12
54
64
20
are
Sunny
Cactus
Comidas
parallevar
Océano
Atlantico
Ltda.
Rancho
grande
Ernst
Handel
ContactName
Address
City
PostalCode
Patricio
Simpson
Cerrito
333
Buenos
Aires
1010
Yvonne
Moncada
Ing.
Gustavo
Moncada
8585
Piso
20-A
Buenos
Aires
1010
Sergio
Gutiérrez
Av.
del
Libertador
900 Buenos
Aires
1010
Roland
Mendel
Kirchgasse
6 Graz
8010
am
bp
OR
CHUSB
CHE
Cg
Country
Venezuela
Venezuela
Venezuela
Venezuela
Country
Argentina
Argentina
Argentina
Austria
7. The following SQL statement inserts a new record in the "Customers" table:
8. The following SQL lists all customers with a NULL value in the “Address” field:
9. The following SQL statement deletes all rows in the “Customers” table, without deleting
the table:
10. The following SQL statement finds the price of the cheapest product:
SQL
Statement:
select max(price)
as
largestprice
from
products;
Edit
the
SQL
Statement,
and
click
"Run
SQL"
to
see
the
result.
Run
SQL
»
Result:
Number
of
Records:
1
largestprice
263.5
‘aiting
for
securepubads.g.doubleclicknnet...
are
sunny
te
aan
Boa
bp
OdDeC@LB@CHBE:
6a