human
Schema:
Manufacturers (Code, Name, Headquarter, Founder, Revenue)
Products (Code, Name, Price, Manufacturer)
Please answer with SQL.
assistant
Sure, I understand.
human
Find the name, headquarter and revenue of all manufacturers sorted by their revenue in the descending order.
assistant
SELECT name , headquarter , revenue FROM manufacturers ORDER BY revenue DESC
human
Find the total revenue for each manufacturer.
assistant
SELECT sum(revenue) , name FROM manufacturers GROUP BY name
human
Find the name and revenue of the company that earns the highest revenue in each city.
assistant
SELECT name , max(revenue) , Headquarter FROM manufacturers GROUP BY Headquarter
human
Find the number of manufactures that are based in Tokyo or Beijing.
assistant
SELECT count(*) FROM manufacturers WHERE headquarter = 'Tokyo' OR headquarter = 'Beijing'
human
Find the number of products for each manufacturer, showing the name of each company.
assistant
SELECT count(*) , T2.name FROM products AS T1 JOIN manufacturers AS T2 ON T1.Manufacturer = T2.code GROUP BY T2.name
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 ;