gpt4 book ai didi

mysql - 如何在mySql中选择值

转载 作者:行者123 更新时间:2023-11-30 22:12:35 25 4
gpt4 key购买 nike

    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

请建议我如何编写内部程序,以便我可以获得像给定结构一样的值我能够在所有分配的值 1、应用值 1 中获得值……但我无法选择值以便获得所需的值。

最佳答案

看看这个:

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

union all

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

关于mysql - 如何在mySql中选择值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39585979/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com