How do I select a field multiple times based on different criteria after a join?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • mlakarex
    New Member
    • Feb 2010
    • 1

    How do I select a field multiple times based on different criteria after a join?

    I'm fairly new at all of this, so if you can endure my explanation and offer any help, I would be most grateful.

    We have 4 groups of individual tasks (all unique)
    Each task is assigned to a campus.

    within the groupings the tasks are sequential, the groups however are not sequential. Each group contains ~ 6 tasks.

    My goal is to query our DB and list the progress in each of the 4 groups based on the completion of tasks within the groups.

    Would it be best to use a Select CASE sequence or IF, or write a function or procedure?

    I'll put in the code I have, but try not to laugh. :)

    Code:
    SELECT DISTINCT
    	fc.name,  tasks.name, tasks.status, 
    	CASE tasks.name 
    		WHEN tasks.name LIKE '1a. Prelim%' /* AND tasks.status = 'Completed'*/ THEN 1
    		WHEN tasks.name LIKE '1b. Prelim%' AND tasks.status = 'Completed' THEN 2
    			ELSE 999
    		END AS 'Rank1'
    	
    	FROM 
    		tasks
    		JOIN users AS u1
    			ON u1.id = tasks.assigned_user_id
    			
    		JOIN focus_campuses_tasks_c AS fct
    			ON tasks.id = focus_campa19fkstasks_idb
    		
    		JOIN focus_campuses_audit AS fca
    			ON fct.focus_campe780ampuses_ida = fca.parent_id
    			
    		JOIN focus_campuses AS fc
    			ON fc.id = focus_campe780ampuses_ida
    			
    		JOIN users AS u2		
    			ON u2.id = fca.after_value_string
    		
    		JOIN tasks_cstm AS tc
    			ON tc.id_c = tasks.id
    			
    		
    			
    	-- WHERE IFNULL(tasks.status, 'Active') <> 'Completed'
    		WHERE tc.auto_campus_expansion_c = 1
    		AND tasks.status <> 'NULL'
    	
    		-- AND tasks.name LIKE '%Prelim%'
    		-- AND tasks.name like '%4%'
    	ORDER BY  fc.name, Rank1, tasks.name, tasks.status  ASC
    	
    	;
    Last edited by Atli; Feb 17 '10, 11:48 PM. Reason: Added [code] tags.
Working...