MySQL Forums
Forum List  »  Stored Procedures

Using UNION for multi query
Posted by: Yamin AbuDaqqa
Date: October 10, 2020 07:44AM

How do I use UNION for multi query

example

set @dept_id='d002';
call new_procedure_total_emp_dept(@dept_id ,@result);

(select dn,staff_title, count(staff_title), (count(staff_title)/@result)*100 from
(
SELECT d.dept_name as dn, ti.title as staff_title FROM dept_emp de
join titles ti using (emp_no)
-- join employees emp using (emp_no)
join departments d on d.dept_no = de.dept_no
where de.dept_no = 'd002'
group by de.emp_no
) as staff_no
group by staff_title
)

union

(
select dn,staff_title, count(staff_title), (count(staff_title)/17786)*100 from
(
SELECT d.dept_name as dn, ti.title as staff_title FROM dept_emp de
join titles ti using (emp_no)
-- join employees emp using (emp_no)
join departments d on d.dept_no = de.dept_no
where de.dept_no = 'd003'
group by de.emp_no
) as staff_no
group by staff_title
)
;

Options: ReplyQuote


Subject
Views
Written By
Posted
Using UNION for multi query
182
October 10, 2020 07:44AM
72
October 10, 2020 10:04AM
72
October 10, 2020 10:52PM
66
October 11, 2020 09:49AM


Sorry, only registered users may post in this forum.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.