MarekMatias

Project3.SQL

Mar 19th, 2017
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
SQL 2.61 KB | None | 0 0
  1.  
  2.  
  3. /* Return the total number of apps in the table fake_apps  */
  4. SELECT MAX(id) FROM fake_apps ;
  5.  
  6. /*Return the name, category, and price of the app that has been downloaded the least amount of times.   */
  7. SELECT name, category , MIN(downloads)
  8. FROM fake_apps;
  9.  
  10. /*Return the total number of apps for each category  */
  11. SELECT category, SUM(downloads)
  12. FROM fake_apps
  13. GROUP BY category;
  14.  
  15. /*Return the name and category of the app that has been downloaded the most amount of times  */
  16. SELECT name, category FROM fake_apps
  17. WHERE downloads = (SELECT MAX(downloads) FROM fake_apps);
  18.  
  19. /*Return the name and category of the app that has been fownloaded the least ammount of times   */
  20. SELECT name , category FROM fake_apps
  21. WHERE downloads = (SELECT MIN(downloads)
  22. FROM fake_apps);
  23.  
  24. /* Return the average price for an app in each category   */
  25. SELECT AVG(price) FROM fake_apps
  26. GROUP BY category;
  27.  
  28. /*Return the average price for an app on each category. Roun the averages to two decimal places  */
  29. SELECT ROUND(AVG(price) ) FROM fake_apps
  30. GROUP BY category;
  31.  
  32. /*Return the maximum price for an app */
  33. SELECT MAX(price) FROM fake_apps;
  34.  
  35. /*Return the minimum number of downloads for an app  */
  36. SELECT MIN(downloads) FROM fake_apps;
  37.  
  38. /*Return the total number of apps that are free */
  39. SELECT COUNT(name) FROM fake_apps
  40. WHERE price = 0;
  41.  
  42. /*Return the total number of apps that cost
  43. 14.99*/
  44. SELECT COUNT(name) FROM fake_apps
  45. WHERE price = 14.99;  
  46.  
  47. /*Return the sum of the total number of downloads for apps that belong to the music category*/
  48. SELECT SUM(downloads) FROM fake_apps
  49. WHERE category =  'Music';
  50.  
  51.  
  52. /*Return the sum of the total numver of downloads for apps that belong to the Business category */
  53. SELECT SUM(downloads) FROM fake_apps
  54. WHERE category ='Business';
  55.  
  56. /*Return the price and average number of downloads grouped by price  */
  57. SELECT category, SUM(downloads)
  58. FROM fake_apps
  59. GROUP BY category;
  60.  
  61. /* Return thep price and average number of downloads grouped by price. Round the averages to the nearest integer.  */
  62. SELECT price , ROUND(AVG(downloads)) FROM fake_apps
  63. GROUP BY price;
  64.  
  65. /*Return the name and category and price of the most expensive app for each category   */
  66. SELECT name, category, MAX(price)
  67. FROM fake_apps;
  68.  
  69.  
  70. /*Return the totalt number of apps whose name begin with the letter 'A'*/
  71. SELECT COUNT(name) FROM fake_apps
  72. WHERE name LIKE '%A';
  73.  
  74.  
  75. /*Return the total number of downloads for apps belonging to the Sports or Health & Fitness category   */
  76. SELECT SUM(downloads) FROM fake_apps
  77. WHERE category =  'Sports'
  78. OR
  79. category = 'Health & Fitness category';
Advertisement
Add Comment
Please, Sign In to add comment