SQL hw1a - Basic Queries Flashcards

1
Q

All columns relating to AAPL

A

SELECT *
FROM stocks.s2010
where symb = ‘AAPL’
;

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

All columns from the table and a column with the
difference between the open and close (open-close)
for AAPL on the 7th of January

A
SELECT *, (opn-cls) as oc_difference
FROM stocks.s2010
WHERE symb = 'AAPL' 
  AND retdate = '2010-01-07'
;
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Write a query which returns the stock symbol, the date,
the open and close price for the top five differences
(open-close) in 2010 for only those stocks on the New
York Stock Exchange

A
SELECT symb, retdate, opn, cls
FROM stocks.s2010
WHERE exch = 'NYSE'
ORDER BY (opn-cls) DESC
LIMIT 5
;
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

The days when AAPL has a volume more than 20 million and where the high is $3 or more greater than the low.

A
SELECT retdate
FROM stocks.s2010
WHERE symb = 'AAPL'
  AND vol >= 20000000
  AND high-low >= 3
;
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Write a query which returns 3 columns: the return date,

SYMB and volume, but only for stocks that have a volume larger than 200 million

A

SELECT retdate, symb, vol
FROM stocks.s2010
WHERE vol > 200000000
;

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Write a query which returns all information about
Google (GOOG), Netflix (NFLX), Amazon (AMZN), and
Microsoft (MSFT) in 2010.

A
SELECT *
FROM stocks.s2010
WHERE symb = 'GOOG'
  OR symb = 'NFLX'
  OR symb = 'AMZN'
  OR symb = 'MSFT'
;
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Write a query which returns the date and symbol of
the largest “one-day gainer”, that is the stock which
has the highest close-open on the NYSE

A
SELECT retdate, symb
FROM stocks.s2010
WHERE exch = 'NYSE'
ORDER BY (cls-opn) DESC
LIMIT 1
;
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

Write a query which returns the date and symbol of the
largest “one-day percentage gainer”, that is the stock
which has the highest (close-open)/open on the NYSE

A
SELECT retdate, symb
FROM stocks.s2010
WHERE exch = 'NYSE'
ORDER BY (cls-opn)/opn DESC
LIMIT 1
;
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

Consider stocks on the NYSE which had a volume of more than 1 million. Which stocks (symb and date) had their open price the same as their low and their closing price the same as their high?

A
SELECT symb, date
FROM stocks.s2010
WHERE exch = 'NYSE'
  AND vol = 1000000
  AND opn = low
  AND cls=high
;
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

Consider stocks on the NYSE which had a volume of more than 1 million. Which stocks (symbol and date) had their closing price the same as their low and their opening price the same as their high?

A
SELECT symb, retdate
FROM stocks.s2010
WHERE exch = 'NYSE'
  AND vol = 1000000
  AND cls = low
  AND opn = high
;
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

Consider stocks on the NYSE which had a volume of more than 1 milion. Of those days which stock had either (a) open = low and close = high, or (b) open = high and close = low, which symbol and date has the largest volume traded?

A
SELECT symb, retdate
FROM stocks.s2010
WHERE exch = 'NYSE'
  AND vol > 1000000
  AND (((opn = low) AND (cls = high)) 
    OR ((opn = high) AND (cls = low)))
ORDER BY vol DESC
LIMIT 1
;
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

Which company (ticker symbol) had the highest net income over all the years that are in the FND tables?

A
SELECT tic
FROM stocks.fnd
ORDER BY netinc DESC NULLS LAST
LIMIT 1
;
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

Which company (ticker symbol) had the highest net income in fiscal year 2011? (using the FND table)

A
SELECT tic
FROM stocks.fnd
WHERE fyear = 2011
ORDER BY netinc DESC NULLS LAST
LIMIT 1
;
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

Which company (ticker symbol) had the lowest, non-zero, net income over all the years? (use the FND table)

A
SELECT tic
FROM stocks.fnd
WHERE netinc > 0
  AND netinc IS NOT NULL
ORDER BY netinc ASC
LIMIT 1
;
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

Which company (ticker symbol) which had a net-income per employee over $1000, had the largest number of employees (over all the years)? Keep units in mind! (use the FND table)

A
SELECT tic
FROM stocks.fnd
WHERE (netinc*1000/emp > 1000)
  AND emp <> 0
  AND emp IS NOT NULL
ORDER BY emp DESC
LIMIT 1
;
How well did you know this?
1
Not at all
2
3
4
5
Perfectly