Need help to optimise MySQL statement

Soldato
Joined
26 Dec 2008
Posts
3,388
Location
Edinburgh
I know some SQL basics but still a newb, I'm trying to get my head around how I combine a number of SELECT statements.

So far I've put together a number of SELECT statements looking up some information on a database.
This is what I have:

Code:
-- This script looks for the tasks with APPROVAL: Page Idea submitted for approval in the name for selected MONTH
SELECT 
    'Page ideas approved' AS 'Stage',
    taskName AS 'TW Task Name',
    DATE_FORMAT(taskCompletedDate, '%M %y') AS 'Month',
    COUNT(*) AS 'Completed'
FROM
    tasks,
    projectcategories
WHERE
    MONTH(taskCompletedDate) = 2
        AND taskName LIKE '%APPROVAL: Page Idea submitted for approval%'
        AND projectCategoryName = 'SF Pages'
        AND taskStatus = 'completed'
GROUP BY taskStatus;

-- This script looks for the tasks with CREATIVE: Writer (commission and track) in the name for selected MONTH
SELECT 
    'Page commissioned' AS 'Stage',
    taskName AS 'TW Task Name',
    DATE_FORMAT(taskStartDate, '%M %y') AS 'Month',
    COUNT(*) AS 'Commissioned'
FROM
    tasks,
    projectcategories
WHERE
    MONTH(taskStartDate) = 2
        AND taskName LIKE '%CREATIVE: Writer (commission and track)%'
        AND projectCategoryName = 'SF Pages'
        AND (taskStatus = 'new'
        OR taskStatus = 'completed')
GROUP BY taskStatus;

-- This script looks for the tasks with CREATIVE: Writer (commission and track) in the name for selected MONTH
SELECT 
    'Page written' AS 'Stage',
    taskName AS 'TW Task Name',
    DATE_FORMAT(taskCompletedDate, '%M %y') AS 'Month',
    COUNT(*) AS 'Completed'
FROM
    tasks,
    projectcategories
WHERE
    MONTH(taskCompletedDate) = 2
        AND taskName LIKE '%CREATIVE: Writer (commission and track)%'
        AND projectCategoryName = 'SF Pages'
        AND taskStatus = 'completed'
GROUP BY taskStatus;

-- This script looks for the tasks with APPROVAL: Copy Approved in the name for selected MONTH
SELECT 
    'Copy approved' AS 'Stage',
    taskName AS 'TW Task Name',
    DATE_FORMAT(taskCompletedDate, '%M %y') AS 'Month',
    COUNT(*) AS 'Completed'
FROM
    tasks,
    projectcategories
WHERE
    MONTH(taskCompletedDate) = 2
        AND taskName LIKE '%APPROVAL: Copy Approved%'
        AND projectCategoryName = 'SF Pages'
        AND taskStatus = 'completed'
GROUP BY taskStatus;


-- This script looks for the tasks with GET LIVE: Is live? in the name for selected MONTH
SELECT 
    'Pages live' AS 'Stage',
    taskName AS 'TW Task Name',
    DATE_FORMAT(taskCompletedDate, '%M %y') AS 'Month',
    COUNT(*) AS 'Completed'
FROM
    tasks,
    projectcategories
WHERE
    MONTH(taskCompletedDate) = 2
        AND taskName LIKE '%GET LIVE: Is live?%'
        AND projectCategoryName = 'SF Pages'
        AND taskStatus = 'completed'
GROUP BY taskStatus;


I'm using MySQL Workbench and the above statements are outputting the results into separate tabs. Ideally I want to run these into one output tab for easy exporting to Excel etc.

Can someone talk me through how to turn the statements into one coherent code?
 
Back
Top Bottom