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
875
October 10, 2020 07:44AM
427
October 10, 2020 10:04AM
387
October 10, 2020 10:52PM
422
October 11, 2020 09:49AM


Sorry, you can't reply to this topic. It has been closed.

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.