如何在mySql中选择值

时间:2016-09-20 04:59:12

标签: mysql

    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

这是我的程序我希望显示这样的值

**label             applied**

 FirstLeave       allocatedvalue1/appliedvalue1
SecondLeave        allocatedvalue2/ appliedvalue2

请建议我如何写procdure内部,以便我可以得到像给定结构的值我能够在所有的allocatevalue1,appliedvalue1 ...中得到值...但我无法选择值,以便我可以获得欲望值。< / p>

1 个答案:

答案 0 :(得分:0)

看看这个:

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

union all

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