Advertisement
TermSpar

Largest Stars database

Apr 12th, 2016
153
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
SQL 3.35 KB | None | 0 0
  1. /*All information from:
  2. https://en.wikipedia.org/wiki/List_of_largest_stars */
  3.  
  4. CREATE TABLE Stars(
  5.     id INTEGER PRIMARY KEY AUTOINCREMENT,
  6.     starName TEXT,
  7.     temp INTEGER,
  8.     solar_radius INTEGER,
  9.     distance INTEGER
  10. );
  11.  
  12. INSERT INTO Stars(starName, temp, solar_radius, distance) VALUES ('UY Scuti', 3365, 1708, 9500);
  13.  
  14. INSERT INTO Stars(starName, temp, solar_radius, distance) VALUES ('NML Cygni', 3250, 2775, 1610);
  15.  
  16. INSERT INTO Stars(starName, temp, solar_radius, distance) VALUES ('WOH G64', 3400, 1540, 163000);
  17.  
  18. INSERT INTO Stars(starName, temp, solar_radius, distance) VALUES ('RW Cephei', 4015, 1535, 3500);
  19.  
  20. INSERT INTO Stars(starName, temp, solar_radius, distance) VALUES ('Westerlund 1-26', 3600, 1530, 11500);
  21.  
  22. INSERT INTO Stars(starName, temp, solar_radius, distance) VALUES ('V354 Cephei', 3650, 1520, 9000);
  23.  
  24. INSERT INTO Stars(starName, temp, solar_radius, distance) VALUES ('VX Sagittarii', 3575, 1520, 5.15);
  25.  
  26. INSERT INTO Stars(starName, temp, solar_radius, distance) VALUES ('VY Canis Majoris', 3490, 1420, 3840);
  27.  
  28. INSERT INTO Stars(starName, temp, solar_radius, distance) VALUES ('KY Cygni', 3500, 1420, 5000);
  29.  
  30. INSERT INTO Stars(starName, temp, solar_radius, distance) VALUES ('AH Scorpii', 3682, 1411, 7400);
  31.  
  32. INSERT INTO Stars(starName, temp, solar_radius, distance) VALUES ('HR 5171 A', 5000, 1316, 11700);
  33.  
  34.  
  35. SELECT starName AS "Name by Solar Radius (H-L)", temp AS "Temperature (Kelvins)", solar_radius AS "Solar Radius (1 =  695,700kl)", Distance AS "Distance (Lightyears)" FROM Stars
  36. ORDER BY solar_radius DESC;
  37.  
  38. SELECT starName AS "Name by Distance (H-L)", temp AS "Temperature (Kelvins)", solar_radius AS "Solar Radius (1 =  695,700kl)", distance AS "Distance (Lighyears)" FROM Stars
  39. ORDER BY distance DESC;
  40.  
  41. SELECT starName AS "Name by Temperature (H-L)", temp AS "Temperature (Kelvins)", solar_radius AS "Solar Radius (1 =  695,700kl)", distance AS "Distance (Lighyears)" FROM Stars
  42. ORDER BY temp DESC;
  43.  
  44. SELECT AVG(solar_radius) AS "Average Radius" FROM Stars;
  45.  
  46.  
  47. SELECT COUNT(*) AS "Number of stars",
  48.     CASE
  49.         WHEN solar_radius > 1608 THEN "Stars ABOVE average solar radius"
  50.         ELSE "Stars BELOW average solar radius"
  51.     END AS Description
  52. FROM Stars
  53. GROUP BY Description;
  54.  
  55.  
  56. SELECT starName AS "Star Name",
  57.     CASE
  58.         WHEN solar_radius >= 1608 THEN "ABOVE average solar radius"
  59.         ELSE "BELOW average solar radius"
  60.     END AS Description
  61. FROM Stars;
  62.  
  63.  
  64. SELECT AVG(temp) AS "Average Temperature" FROM Stars;
  65.  
  66.  
  67. SELECT COUNT(*) AS "Number of stars",
  68.     CASE
  69.         WHEN temp > 3684.2 THEN "stars ABOVE average temperature"
  70.         ELSE "stars BELOW average temperature"
  71.     END AS Description
  72. FROM Stars
  73. GROUP BY Description;
  74.  
  75.  
  76. SELECT starName AS "Star Name",
  77.     CASE
  78.         WHEN temp > 3684.2 THEN "is ABOVE average temperature"
  79.         ELSE "is BELOW average temperature"
  80.     END AS Description
  81. FROM Stars;
  82.  
  83. SELECT AVG(distance) AS "Average Distance" FROM Stars;
  84.  
  85.  
  86. SELECT COUNT(*) AS "Number of stars",
  87.     CASE
  88.         WHEN distance > 20550.4 THEN "stars ABOVE average distance"
  89.         ELSE "stars BELOW average distance"
  90.     END AS Description
  91. FROM Stars
  92. GROUP BY Description;
  93.  
  94.  
  95. SELECT starName AS "Star Name",
  96.     CASE
  97.       WHEN distance > 20550.4 THEN "is ABOVE average distance"
  98.         ELSE "is BELOW average distance"
  99.     END AS Description
  100. FROM Stars;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement