2016-09-20 47 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