WorksheetsIntroduction to SQL
Total questions: 8
Worksheet time: 8mins
How many possible states are there for a Boolean column?
1
2
3
4
What is the difference of Varchar type and Text type?
No difference
Varchar length can be specified but not Text
Text length can be specified but not Varchar
Varchar can take special character but not Text
Which of the following is true?
SQL syntax in PostgreSQL for SELECT, WHERE statements are case sensitive
date / timestamp columns can be cast to a Varchar
We can select columns with null by doing
Select * from Table where Col1 = Null
Postgresql supports addition, subtraction, multiplication, but not division.
What is the output for the following?
SELECT CAST(EXTRACT(Month FROM TIMESTAMP '2016-11-31 13:30:15') as varchar)
November
No output - syntax error
"11"
11
How to correctly truncate a month from timestamp?
SELECT DATE_TRUNCATE('month', TIMESTAMP '2017-03-17 02:09:30')
SELECT DATE_TRUNC(month, TIMESTAMP '2017-03-17 02:09:30')
SELECT DATE_TRUNCATE(TIMESTAMP '2017-03-17 02:09:30','month')
SELECT DATE_TRUNC('month', TIMESTAMP '2017-03-17 02:09:30')
Which of the following is correct PostgrSQL syntax?
select *
from fast_food.orders
where food='fries'
order by 1
limit 3
select *
from fast_food.orders
where food='fries'
limit 3
order by 1
select *
from fast_food.orders
limit 3
order by 1
where food='fries'
select *
from fast_food.orders
where food='fries'
limit 3
order by 1
How to correctly use a LIKE operator to search for text containing "Abc"?
Select * from Table where text LIKE %Abc%
Select * from Table where text LIKE '$Abc$'
Select * from Table where text LIKE '%Abc%'
Select * from Table where text LIKE ~Abc~
What is not a right way to handle NULL values?
Order by so NULLS will appear last
use WHERE filter where Col1 is not NULL
Coalesce the NULL value to become another value such as 0
cast Null as INT type to get 0
