gpt4 book ai didi

sql - 如何删除 '2002' 和 '2006' 之间的特定键?

转载 作者:行者123 更新时间:2023-12-05 02:36:25 25 4
gpt4 key购买 nike

这是我想在这里处理的考试数据表:

-原始数据

<表类="s-表"><头>STU_IDSTU_KEYSTU_CODE<正文>1232002123A1201242002124A1201252002125A1201262002126A1201272002127A1201282003123A1201292003124A1201302004123A1201312005123A1201322006123A1201332007123A1201342008321A120

我想使用 SAS proc sql 的代码删除特定键的行,包括“2002”和“2006”之间的行。

-结果数据

<表类="s-表"><头>STU_IDSTU_KEYSTU_CODE<正文>1332007123A1201342008321A120
 '''error code'''
PROC SQL;
CREATE TABLE a.not_2002_2006 as
SELECT t.STU_ID,
t.STU_KEY,
t.STU_CODE
FROM a.stu as t
WHERE t.STU_KEY NOT LIKE '2002%'
and t.STU_KEY NOT LIKE '2003%'
and t.STU_KEY NOT LIKE '2004%'
and t.STU_KEY NOT LIKE '2005%'
and t.STU_KEY NOT LIKE '2006%'
GROUP BY t.STU_ID;
QUIT;

让我知道如何解决这个问题。

最佳答案

您可能遇到了 LIKE operator requires character operands 错误。如果是这种情况,这是因为您的 STU_KEY 是数字列。使用 PUT 调整 where 语句以将 like 运算符与字符列一起使用功能。

proc sql;
create table want as select stu_id, stu_key, stu_code
from have
where put(stu_key, 7.) like '2007%'
or put(stu_key, 7.) like '2008%'
group by stu_id;
quit;

输出:

enter image description here

关于sql - 如何删除 '2002' 和 '2006' 之间的特定键?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/70256581/

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