我想在我的Aginity Netezza宏中添加一个名字列表。例如,我希望能够在将来的查询中重复使用列表("Adam“、"Bill”、"Cynthia“、"Dick”、"Ella“、"Fanny"),例如在WHERE子句中。
我的问题是:(1)我可以在Query Parameters Editor的"Value“窗口中输入多少个字符有限制吗?(2)有没有一种方法可以在不使用宏的情况下实现这一点?例如,在某个地方预定义这个列表?
发布于 2018-08-10 06:15:45
我会将列表放到一个(临时)表中,并在必要时简单地加入其中:
Create temp table names as
Select ‘Adam’::varchar(50)
Union all Select ‘Bill’::varchar(50)
Union all Select ‘Cynthia’::varchar(50)
Union all Select ‘Dick’::varchar(50)
Union all Select ‘Ella’::varchar(50)
Union all Select ‘Fanny’
;
Select x.a,x.b
from x
where x.name in (select * from Names)
;
Select
case
when x.name in (select * from Names)
then ‘Special’
Else ‘Other’
End as NameGrp,
Count(*) as size,
Sum(income) as TotalIncome
Group by NameGrp
Order by size desc
;或者,netezza有一个支持数组数据类型的扩展工具包,但如果您将其用于该目的,则第一个查询将不能很好地执行。有兴趣吗?查看这里:https://www.ibm.com/support/knowledgecenter/en/SSULQD_7.2.1/com.ibm.nz.sqltk.doc/c_sqlext_array.html或谷歌的例子
https://stackoverflow.com/questions/51766037
复制相似问题