Practice-Astronauts EVAs
  • AI Chat
  • Code
  • Report
  • Beta
    Spinner

    Explore Extra Vehicular Activities (EVAs) of Astronauts

    • Dataset consists of the following:
      • USA Space programs ranging from 1965-2013
      • Description of activities performed
    Unknown integration
    DataFrameavailable as
    overview
    variable
    -- Start writing your SQL query here 
    
    SELECT * FROM evas LIMIT 10;
    This query is taking long to finish...Consider adding a LIMIT clause or switching to Query mode to preview the result.
    Unknown integration
    DataFrameavailable as
    df
    variable
    SELECT COUNT(DISTINCT(purpose)) AS unique_purposes FROM evas;
    This query is taking long to finish...Consider adding a LIMIT clause or switching to Query mode to preview the result.

    Categorize EVA purposes based on keywords

    Unknown integration
    DataFrameavailable as
    df
    variable
    SELECT purpose,
    	CASE WHEN purpose LIKE '%install%' OR purpose LIKE '%construct%' THEN 1 ELSE 0 END AS installation,
        CASE WHEN purpose LIKE '%photo%' THEN 1 ELSE 0 END AS photography,
        CASE WHEN purpose LIKE '%collect%' THEN 1 ELSE 0 END AS collection,
        CASE WHEN purpose LIKE '%recover%' OR purpose LIKE '%retrieve%' THEN 1 ELSE 0 END AS retrieval,
        CASE WHEN purpose LIKE '%Jjettison%' THEN 1 ELSE 0 END AS jettison,
        CASE WHEN purpose LIKE '%repair%' OR purpose LIKE '%fix%' OR purpose LIKE '%replace%' OR purpose LIKE '%service%' THEN 1 ELSE 0 END AS repair
    FROM evas;
        
    This query is taking long to finish...Consider adding a LIMIT clause or switching to Query mode to preview the result.
    Unknown integration
    DataFrameavailable as
    df
    variable
    -- Using ILIKE (case-insensitive) instead of LIKE (case-sensitive)
    
    
    WITH purposes AS(
        SELECT purpose,
            CASE WHEN purpose ILIKE '%install%' OR purpose ILIKE '%construct%' OR purpose ILIKE '%assembl%' THEN 1 ELSE 0 END AS installation,
            CASE WHEN purpose ILIKE '%photo%' THEN 1 ELSE 0 END AS photography,
            CASE WHEN purpose ILIKE '%collect%' THEN 1 ELSE 0 END AS collection,
            CASE WHEN purpose ILIKE '%recover%' OR purpose ILIKE '%retrieve%' THEN 1 ELSE 0 END AS retrieval,
            CASE WHEN purpose ILIKE '%jettison%' THEN 1 ELSE 0 END AS jettison,
            CASE WHEN purpose ILIKE '%repair%' OR purpose ILIKE '%fix%' OR purpose ILIKE '%replace%' OR purpose ILIKE '%servic%' THEN 1 ELSE 0 END AS repair
        FROM evas
    )
        
        
    SELECT 'installation' AS type, SUM(installation) AS total
    FROM purposes
    UNION
    SELECT 'photography' AS type, SUM(photography) AS total
    FROM purposes
    UNION
    SELECT 'collection' AS type, SUM(collection) AS total
    FROM purposes
    UNION
    SELECT 'retrieval' AS type, SUM(retrieval) AS total
    FROM purposes
    UNION
    SELECT 'jettison' AS type, SUM(jettison) AS total
    FROM purposes
    UNION
    SELECT 'repair' AS type, SUM(repair) AS total
    FROM purposes
    ORDER BY total;
    
    
    This query is taking long to finish...Consider adding a LIMIT clause or switching to Query mode to preview the result.
    Current Type: Bar
    Current X-axis: total
    Current Y-axis: type
    Current Color: None

    EVAs categorized by keywords and label activity types

    Calculate Total Geological Samples collected in lbs

    Unknown integration
    DataFrameavailable as
    df
    variable
    --Filter purpose for Geological samples collection
    
    SELECT purpose 
    FROM evas
    WHERE purpose ILIKE '%rock%' OR purpose ILIKE '%geologic%';
    This query is taking long to finish...Consider adding a LIMIT clause or switching to Query mode to preview the result.
    Unknown integration
    DataFrameavailable as
    df
    variable
    --Using Regex symbols to extract weight from EVA description
    
    SELECT
    	purpose,
        SUBSTRING(purpose, '\d+\.?\d*') AS weight
    FROM evas
    WHERE purpose ILIKE '%rock%' OR purpose ILIKE '%geologic%';
    This query is taking long to finish...Consider adding a LIMIT clause or switching to Query mode to preview the result.
    Unknown integration
    DataFrameavailable as
    df
    variable
    --Prepare CTE and calculate total_rock_collections weight
    
    WITH rock_collections AS (
    	SELECT
        purpose,
        SUBSTRING(purpose, '\d+\.?\d*')::NUMERIC AS weight
        FROM evas
        WHERE purpose ILIKE '%rock%' OR purpose ILIKE '%geologic%'
    )
    
    
    SELECT SUM(weight) AS total_rock_collections 
    FROM rock_collections;
    This query is taking long to finish...Consider adding a LIMIT clause or switching to Query mode to preview the result.

    Calculate Astronauts' individual EVA duration

    Unknown integration
    DataFrameavailable as
    df
    variable
    --Split multiple Astronaut names from crew
    
    SELECT 
    	crew,
        SPLIT_PART(crew, ',', 1) AS first_astronaut,
    	SPLIT_PART(crew, ',', 2) AS second_astronaut,
    	SPLIT_PART(crew, ',', 3) AS third_astronaut
    FROM evas;
    This query is taking long to finish...Consider adding a LIMIT clause or switching to Query mode to preview the result.
    Unknown integration
    DataFrameavailable as
    df
    variable
    -- Prepare & Use CTEs (astronauts_list and astronauts_duration)
    
    WITH astronauts_list AS (
    	SELECT 
    	crew, duration,
        SPLIT_PART(crew, ',', 1) AS first_astronaut,
    	SPLIT_PART(crew, ',', 2) AS second_astronaut,
    	SPLIT_PART(crew, ',', 3) AS third_astronaut
    	FROM evas
    ),
    
    astronauts_duration AS (
    	SELECT first_astronaut AS astronaut, duration
        FROM astronauts_list
        WHERE first_astronaut != ''
        UNION ALL
        SELECT second_astronaut AS astronaut, duration
        FROM astronauts_list
        WHERE second_astronaut != ''
        UNION ALL
        SELECT third_astronaut AS astronaut, duration
        FROM astronauts_list
        WHERE third_astronaut != ''
    )
    
    
    
    SELECT astronaut, SUM(duration) AS total_duration
    FROM astronauts_duration
    GROUP BY astronaut
    ORDER BY total_duration DESC
    LIMIT 15;
    This query is taking long to finish...Consider adding a LIMIT clause or switching to Query mode to preview the result.
    Current Type: Bar
    Current X-axis: total_duration
    Current Y-axis: astronaut
    Current Color: None

    Total Duration of EVAs by each Astronaut