Given a table with an id and value column, write a SQL query that returns the average value for each id.
To find the median value for each id in a table of data, you can use a query like the following: SELECT id, MAX(CASE WHEN rn = 1 THEN value END) AS median FROM (SELECT id, value, ROW_NUMBER() OVER (PARTITION BY id ORDER BY value) AS rn FROM data WHERE id IS NOT NULL) AS d GROUP BY id HAVING COUNT(*) % 2 = 1;
Write a SQL query to find the cheapest product in a given table. The table schema is provided, and an example input and output are given.
Given a table of data with columns for name, email, and signup date, this SQL query will find the most recent signup for each email address.
To find the products with the highest price-to-quality ratio, divide the price by the quality for each product. The product with the highest ratio is the product with the highest price- to-quality ratio.
Given a table of data with people's names and addresses, write a SQL query to find all the people who live in the same city as 'John Smith'.
Write a SQL query to find the total sales for each day from a table of sales information.
To find the average price of all products in a table, write a SQL query that calculates the sum of all prices divided by the count of all prices.