2016-09-20 49 views
1
CREATE DEFINER=`root`@`localhost` PROCEDURE `My_PRO`(in employeId int) 
    BEGIN 
    declare allocatedvalue1 int default 0; 
    declare allocatedvalue2 int default 0; 
    declare appliedvalue1 int default 0; 
    declare appliedvalue2 int default 0; 

set allocatedvalue1=(
    SELECT sum(day) FROM Parabola.leave_allocated where employee_id=741 and 
    leave_type_id=42 and year='2016') ; 

    set appliedvalue1=(
    select IFNULL(FORMAT(sum(hours/8),1),0)from leave_applied where 
    employee_id=741 and leave_type_id in(42) and status in (1,2,5)and 
    (start_date>='2016-01-01' 
    and end_date<='2016-12-31')); 

    set allocatedvalue2=(

    select sum(day) from compensatory_leave where 
    employee_id=741 and status in(2,3));  

    set appliedvalue2=(
    select sum(day) from compensatory_leave where 
    employee_id=741);  
    END 

这是我的过程我要显示这样如何在MySQL中选择价值

**label    applied** 

FirstLeave  allocatedvalue1/appliedvalue1 
SecondLeave  allocatedvalue2/ appliedvalue2 

值请建议我里面怎么procdure写,这样我可以得到这样给定结构值,我能够在所有分配的价值中获得价值1,appliedvalue1 ...但我无法选择价值,因此我可以获得愿望值。

+0

在一份报告表,可以随时堵塞你的数据,并在年底做一个选择,从它。也就是说,mysql是一个RDBMS。你为什么试图制作一个报表引擎? – Drew

回答

0

看看这个:

select 'FirstLeave' as FirstLeave,allocatedvalue1/appliedvalue1 as fvalue1 

union all 

select 'SecondLeave' as SecondLeave,  allocatedvalue2/ appliedvalue2 as fvalue2