0% found this document useful (0 votes)
61 views

Query 1:: Unique Liquor Stores in Iowa

The document contains 6 SQL queries analyzing liquor sales data from Iowa and flight data. The first 3 queries analyze the Iowa liquor data by counting unique stores, summarizing sales by store and year, and exploring the store locations in a GIS viewer. The last 3 queries analyze airline flight data by total flights by airline, flights by airline and year, and Southwest flights in 2012 grouped by departure and arrival airports.

Uploaded by

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

Query 1:: Unique Liquor Stores in Iowa

The document contains 6 SQL queries analyzing liquor sales data from Iowa and flight data. The first 3 queries analyze the Iowa liquor data by counting unique stores, summarizing sales by store and year, and exploring the store locations in a GIS viewer. The last 3 queries analyze airline flight data by total flights by airline, flights by airline and year, and Southwest flights in 2012 grouped by departure and arrival airports.

Uploaded by

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

Query 1: Unique liquor stores in Iowa

SELECT
count(DISTINCT( store_number)) AS storenum
FROM
`bigquery-public-data.iowa_liquor_sales.sales`
ORDER BY
storenum

Query 2: Storewise sales in liters by year

SELECT
store_number,
upper(store_name) as store_name,
upper(county) as county,
EXTRACT() as wkt,
ROUND(SUM(volume_sold_liters),2) AS liters_sold
FROM
`bigquery-public-data.iowa_liquor_sales.sales`
GROUP BY
store_number,
store_name,
county,
store_location
ORDER BY
store_number,
store_name,
store_location,
liters_sold DESC

Query 3: Explore on GIS viewer

SELECT
store_number,
upper(store_name) as store_name,
upper(county) as county,
ST_GEOGFROMTEXT(store_location) as wkt,
ROUND(SUM(volume_sold_liters),2) AS liters_sold
FROM
`bigquery-public-data.iowa_liquor_sales.sales`
GROUP BY
store_number,
store_name,
county,
store_location
Query 4: Airlines by the total number of flights they have operated

SELECT
airline AS airline,
airline_code AS airlineCode,
nameOfAirline,
COUNT(*) numFlights
FROM
[bigquery-samples:airline_ontime_data.flights] AS flights
JOIN (
SELECT
airline nameOfAirline,
code
FROM
[bigquery-samples:airline_ontime_data.airline_id_codes]) AS codes
ON
flights.airline_code = codes.code
GROUP BY
airline,
airlineCode,
nameOfAirline
ORDER BY
numFlights DESC

Query 5: Airlines by the number of flights they have operated each year

SELECT
airline as airline,
airline_code AS airlineCode,
nameOfAirline,
YEAR(date) AS year,
COUNT(*) numFlights
FROM
[bigquery-samples:airline_ontime_data.flights] AS flights
JOIN (
SELECT
airline nameOfAirline,
code
FROM
[bigquery-samples:airline_ontime_data.airline_id_codes]) AS codes
ON
flights.airline_code = codes.code
GROUP BY
year,
airline,
airlineCode,
nameOfAirline
ORDER BY
year,
numFlights DESC

Query 6: Flights operated by Southwest during 2012

SELECT
departure_airport DEP,
arrival_airport ARR,
COUNT(*) numFlights
FROM
[bigquery-samples:airline_ontime_data.flights]
WHERE
YEAR(date) = 2012
AND airline_code = '19393'
GROUP BY
DEP,
ARR
ORDER BY
numFlights DESC

You might also like