Database: phone_market

Question: Show the names of phones with carrier either "Sprint" or "TMobile".
SQL: SELECT Name FROM phone WHERE Carrier  =  "Sprint" OR Carrier  =  "TMobile"

Question: What is the carrier of the most expensive phone?
SQL: SELECT Carrier FROM phone ORDER BY Price DESC LIMIT 1

Question: Show the most frequently used carrier of the phones.
SQL: SELECT Carrier FROM phone GROUP BY Carrier ORDER BY COUNT(*) DESC LIMIT 1

Question: Show the carriers that have both phones with memory smaller than 32 and phones with memory bigger than 64.
SQL: SELECT Carrier FROM phone WHERE Memory_in_G  <  32 INTERSECT SELECT Carrier FROM phone WHERE Memory_in_G  >  64

Question: Show the names of phones and the districts of markets they are on.
SQL: SELECT T3.Name ,  T2.District FROM phone_market AS T1 JOIN market AS T2 ON T1.Market_ID  =  T2.Market_ID JOIN phone AS T3 ON T1.Phone_ID  =  T3.Phone_ID

Question: Show the names of phones and the districts of markets they are on, in ascending order of the ranking of the market.
SQL: SELECT T3.Name ,  T2.District FROM phone_market AS T1 JOIN market AS T2 ON T1.Market_ID  =  T2.Market_ID JOIN phone AS T3 ON T1.Phone_ID  =  T3.Phone_ID ORDER BY T2.Ranking

Question: Show the names of phones that are on market with number of shops greater than 50.
SQL: SELECT T3.Name FROM phone_market AS T1 JOIN market AS T2 ON T1.Market_ID  =  T2.Market_ID JOIN phone AS T3 ON T1.Phone_ID  =  T3.Phone_ID WHERE T2.Num_of_shops  >  50

Question: For each phone, show its names and total number of stocks.
SQL: SELECT T2.Name ,  sum(T1.Num_of_stock) FROM phone_market AS T1 JOIN phone AS T2 ON T1.Phone_ID  =  T2.Phone_ID GROUP BY T2.Name

Question: Show the names of phones that have total number of stocks bigger than 2000, in descending order of the total number of stocks.
SQL: SELECT T2.Name FROM phone_market AS T1 JOIN phone AS T2 ON T1.Phone_ID  =  T2.Phone_ID GROUP BY T2.Name HAVING sum(T1.Num_of_stock)  >=  2000 ORDER BY sum(T1.Num_of_stock) DESC