gpt4 book ai didi

mysql - 从 MySQL 数据库表中选择行时如何使特定列值的第一行为空

转载 作者:行者123 更新时间:2023-11-29 13:07:49 25 4
gpt4 key购买 nike

注意:当从数据库表中选择行时,我希望将第一行 TParent_Group_ID 设为空

BEGIN    DECLARE done INT DEFAULT 0;    DECLARE next_id INT;    -- CURSOR TO LOOP THROUGH RESULTS --    DECLARE cur1 CURSOR FOR SELECT GID FROM civicsoft_group WHERE Parent_Group_ID = GivenID;    DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = 1;    -- CREATE A TEMPORARY TABLE TO HOLD RESULTS --    IF initial=1 THEN        -- MAKE SURE TABLE DOESN'T CONTAIN OUTDATED INFO IF IT EXISTS (USUALLY ON ERROR) --        DROP TABLE IF EXISTS OUT_TEMP;         CREATE TEMPORARY TABLE OUT_TEMP (TGID int,TParent_Group_ID int, TGroup_Name varchar(32),TGroup_Type varchar(1),TProject_Status tinyint(1),TEID int,TEmp_Group_ID int,TEmp_Name varchar(100),TEmp_Type varchar(2));    END IF;    -- ADD OURSELF TO THE TEMPORARY TABLE --    INSERT INTO OUT_TEMP SELECT cg.GID,cg.Parent_Group_ID,cg.Group_Name,cg.Group_Type,cg.Project_Status,ce.EID,ce.Emp_Group_ID,ce.Emp_Name,ce.Emp_Type FROM civicsoft_group cg LEFT JOIN civicsoft_employee ce ON cg.GID = ce.Emp_Group_ID  WHERE cg.GID = GivenID;    -- AND LOOP THROUGH THE CURSOR --    OPEN cur1;    read_loop: LOOP        FETCH cur1 INTO next_id;        -- NO ROWS FOUND, LEAVE LOOP --        IF done THEN        LEAVE read_loop;        END IF;        -- NEXT ROUND --    SET @@GLOBAL.max_sp_recursion_depth = 255;    SET @@session.max_sp_recursion_depth = 255;         CALL Hierarchy(next_id, 0);         END LOOP;    CLOSE cur1;    -- THIS IS THE INITIAL CALL, LET'S GET THE RESULTS --    IF initial=1 THEN         SELECT * FROM OUT_TEMP;  -- Producing Final Temporary Table output        -- CLEAN UP AFTER OURSELVES --        DROP TABLE OUT_TEMP;     END IF;END

最佳答案

创建特殊第一行的一般解决方案是:

select 0, null, null, ...
union all
select *
from ...
where ...

第一行的列数和类型必须与第二个选择完全相同。您可以为第一行选择任何您喜欢的特殊值,只要编码的值与列类型兼容即可。

关于mysql - 从 MySQL 数据库表中选择行时如何使特定列值的第一行为空,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22474283/

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