human
Schema:
Manufacturers (Code, Name, Headquarter, Founder, Revenue)
Products (Code, Name, Price, Manufacturer)
Please answer with SQL.
assistant
Sure, I understand.
human
Find the number of different products that are produced by companies at different headquarter cities.
assistant
SELECT count(DISTINCT T1.name) , T2.Headquarter FROM products AS T1 JOIN manufacturers AS T2 ON T1.Manufacturer = T2.code GROUP BY T2.Headquarter
human
Find the name of companies whose revenue is greater than the average revenue of all companies.
assistant
SELECT name FROM manufacturers WHERE revenue > (SELECT avg(revenue) FROM manufacturers)
human
What is the total revenue of all companies whose main office is at Tokyo or Taiwan?
assistant
SELECT sum(revenue) FROM manufacturers WHERE Headquarter = 'Tokyo' OR Headquarter = 'Taiwan'
human
What are the average, maximum and total revenues of all companies?
assistant
SELECT avg(revenue) , max(revenue) , sum(revenue) FROM manufacturers
human
Find the name, headquarter and founder of the manufacturer that has the highest revenue.
assistant
SELECT name , headquarter , founder FROM manufacturers ORDER BY revenue DESC LIMIT 1
human
What are the names and revenues of the companies with the highest revenues in each headquarter city?
assistant
SELECT name , MAX( revenue ) , Headquarter FROM manufacturers GROUP BY Headquarter ;