|
description,query |
|
Get all records from fund_data,SELECT * FROM fund_data; |
|
Get all records from fund_data,SELECT * FROM fund_data; |
|
Get all unique fund names,SELECT DISTINCT scheme_name FROM fund_data; |
|
Get the latest price for each fund," |
|
SELECT scheme_name, sale_price_per_unit |
|
FROM fund_data |
|
WHERE (scheme_name, date_valued) IN ( |
|
SELECT scheme_name, MAX(date_valued) |
|
FROM fund_data |
|
GROUP BY scheme_name |
|
); |
|
" |
|
Get the total sale_price_per_unit for each fund,"SELECT scheme_name, SUM(sale_price_per_unit) FROM fund_data GROUP BY scheme_name;" |
|
Get the number of records for each fund,"SELECT scheme_name, COUNT(*) FROM fund_data GROUP BY scheme_name;" |
|
Get the earliest and latest date_valued for each fund,"SELECT scheme_name, MIN(date_valued), MAX(date_valued) FROM fund_data GROUP BY scheme_name;" |
|
Get the sale_price_per_unit for the latest date_valued for each fund," |
|
SELECT scheme_name, sale_price_per_unit |
|
FROM fund_data |
|
WHERE date_valued = ( |
|
SELECT MAX(date_valued) |
|
FROM fund_data AS fd |
|
WHERE fd.scheme_name = fund_data.scheme_name |
|
); |
|
" |
|
Get the fund with the highest average sale_price_per_unit for each year," |
|
SELECT YEAR(date_valued) AS year, scheme_name, AVG(sale_price_per_unit) AS avg_price |
|
FROM fund_data |
|
GROUP BY year, scheme_name |
|
ORDER BY avg_price DESC; |
|
" |
|
Get the fund with the highest total sale_price_per_unit for each month in 2020," |
|
SELECT MONTH(date_valued) AS month, scheme_name, SUM(sale_price_per_unit) AS total_price |
|
FROM fund_data |
|
WHERE YEAR(date_valued) = 2020 |
|
GROUP BY month, scheme_name |
|
ORDER BY total_price DESC; |
|
" |
|
Get the top 3 funds with the highest average sale_price_per_unit for each quarter in 2020," |
|
SELECT QUARTER(date_valued) AS quarter, scheme_name, AVG(sale_price_per_unit) AS avg_price |
|
FROM fund_data |
|
WHERE YEAR(date_valued) = 2020 |
|
GROUP BY quarter, scheme_name |
|
ORDER BY avg_price DESC |
|
LIMIT 3; |
|
" |
|
Get the fund with the highest sale_price_per_unit for the last date_valued of each month in 2020," |
|
SELECT scheme_name, sale_price_per_unit |
|
FROM fund_data |
|
WHERE date_valued IN ( |
|
SELECT MAX(date_valued) |
|
FROM fund_data |
|
WHERE YEAR(date_valued) = 2020 |
|
GROUP BY MONTH(date_valued) |
|
) |
|
ORDER BY sale_price_per_unit DESC; |
|
" |
|
Get the fund with the lowest average sale_price_per_unit," |
|
SELECT scheme_name, AVG(sale_price_per_unit) AS avg_price |
|
FROM fund_data |
|
GROUP BY scheme_name |
|
ORDER BY avg_price ASC |
|
LIMIT 1; |
|
" |
|
Get the date with the highest total sale_price_per_unit for all funds," |
|
SELECT date_valued, SUM(sale_price_per_unit) AS total_price |
|
FROM fund_data |
|
GROUP BY date_valued |
|
ORDER BY total_price DESC |
|
LIMIT 1; |
|
" |
|
Get the fund with the most records in the database," |
|
SELECT scheme_name, COUNT(*) AS count |
|
FROM fund_data |
|
GROUP BY scheme_name |
|
ORDER BY count DESC |
|
LIMIT 1; |
|
" |
|
Get the date with the most records in the database," |
|
SELECT date_valued, COUNT(*) AS count |
|
FROM fund_data |
|
GROUP BY date_valued |
|
ORDER BY count DESC |
|
LIMIT 1; |
|
" |
|
Get the fund with the highest sale_price_per_unit on the latest date_valued," |
|
SELECT scheme_name, sale_price_per_unit |
|
FROM fund_data |
|
WHERE date_valued = ( |
|
SELECT MAX(date_valued) |
|
FROM fund_data |
|
) |
|
ORDER BY sale_price_per_unit DESC |
|
LIMIT 1; |
|
" |
|
Get the percentage change in average sale_price_per_unit from the previous month for each fund in 2020," |
|
SELECT scheme_name, MONTH(date_valued) AS month, |
|
((AVG(sale_price_per_unit) - LAG(AVG(sale_price_per_unit)) OVER (PARTITION BY scheme_name ORDER BY month)) / LAG(AVG(sale_price_per_unit)) OVER (PARTITION BY scheme_name ORDER BY month)) * 100 AS pct_change |
|
FROM fund_data |
|
WHERE YEAR(date_valued) = 2020 |
|
GROUP BY scheme_name, month; |
|
" |
|
Get the top 5 funds with the highest average sale_price_per_unit," |
|
SELECT scheme_name, AVG(sale_price_per_unit) AS avg_price |
|
FROM fund_data |
|
GROUP BY scheme_name |
|
ORDER BY avg_price DESC |
|
LIMIT 5; |
|
" |
|
Calculate percentage return of funds in 2020," |
|
SELECT |
|
start_price.scheme_name, |
|
((end_price.sale_price_per_unit - start_price.sale_price_per_unit) / start_price.sale_price_per_unit) * 100 AS percentage_return |
|
FROM |
|
(SELECT scheme_name, sale_price_per_unit |
|
FROM fund_data |
|
WHERE scheme_name IN ('Liquid Fund', 'Bond Fund') AND date_valued = (SELECT MIN(date_valued) FROM fund_data WHERE scheme_name = fund_data.scheme_name) |
|
GROUP BY scheme_name) AS start_price, |
|
(SELECT scheme_name, sale_price_per_unit |
|
FROM fund_data |
|
WHERE scheme_name IN ('Liquid Fund', 'Bond Fund') AND date_valued = (SELECT MAX(date_valued) FROM fund_data WHERE scheme_name = fund_data.scheme_name) |
|
GROUP BY scheme_name) AS end_price |
|
WHERE start_price.scheme_name = end_price.scheme_name; |
|
" |
|
Calculate Sharpe Ratio of Liquid Fund in 2020," |
|
SELECT |
|
scheme_name, |
|
AVG(daily_return) AS avg_return, |
|
STDDEV_POP(daily_return) AS std_dev, |
|
(AVG(daily_return) - 12) / STDDEV_POP(daily_return) AS sharpe_ratio |
|
FROM |
|
(SELECT |
|
scheme_name, |
|
((sale_price_per_unit - LAG(sale_price_per_unit) OVER (PARTITION BY scheme_name ORDER BY date_valued)) / LAG(sale_price_per_unit) OVER (PARTITION BY scheme_name ORDER BY date_valued)) * 100 AS daily_return |
|
FROM |
|
fund_data |
|
WHERE |
|
scheme_name = 'Liquid Fund' AND YEAR(date_valued) = 2020) AS daily_returns |
|
GROUP BY |
|
scheme_name; |
|
" |
|
Get the total number of records in fund_data,SELECT COUNT(*) FROM fund_data; |
|
Get the average sale_price_per_unit for each fund,"SELECT scheme_name, AVG(sale_price_per_unit) FROM fund_data GROUP BY scheme_name;" |
|
Get all unique fund names,SELECT DISTINCT scheme_name FROM fund_data; |
|
Get the latest price for each fund," |
|
SELECT scheme_name, sale_price_per_unit |
|
FROM fund_data |
|
WHERE (scheme_name, date_valued) IN ( |
|
SELECT scheme_name, MAX(date_valued) |
|
FROM fund_data |
|
GROUP BY scheme_name |
|
); |
|
" |
|
Calculate percentage return of funds in 2020," |
|
SELECT |
|
start_price.scheme_name, |
|
((end_price.sale_price_per_unit - start_price.sale_price_per_unit) / start_price.sale_price_per_unit) * 100 AS percentage_return |
|
FROM |
|
(SELECT scheme_name, sale_price_per_unit |
|
FROM fund_data |
|
WHERE scheme_name IN ('Liquid Fund', 'Bond Fund') AND date_valued = (SELECT MIN(date_valued) FROM fund_data WHERE scheme_name = fund_data.scheme_name) |
|
GROUP BY scheme_name) AS start_price, |
|
(SELECT scheme_name, sale_price_per_unit |
|
FROM fund_data |
|
WHERE scheme_name IN ('Liquid Fund', 'Bond Fund') AND date_valued = (SELECT MAX(date_valued) FROM fund_data WHERE scheme_name = fund_data.scheme_name) |
|
GROUP BY scheme_name) AS end_price |
|
WHERE start_price.scheme_name = end_price.scheme_name; |
|
" |
|
Calculate Sharpe Ratio of Liquid Fund in 2020," |
|
SELECT |
|
scheme_name, |
|
AVG(daily_return) AS avg_return, |
|
STDDEV_POP(daily_return) AS std_dev, |
|
(AVG(daily_return) - 12) / STDDEV_POP(daily_return) AS sharpe_ratio |
|
FROM |
|
(SELECT |
|
scheme_name, |
|
((sale_price_per_unit - LAG(sale_price_per_unit) OVER (PARTITION BY scheme_name ORDER BY date_valued)) / LAG(sale_price_per_unit) OVER (PARTITION BY scheme_name ORDER BY date_valued)) * 100 AS daily_return |
|
FROM |
|
fund_data |
|
WHERE |
|
scheme_name = 'Liquid Fund' AND YEAR(date_valued) = 2020) AS daily_returns |
|
GROUP BY |
|
scheme_name; |
|
" |
|
|