gpt4 book ai didi

postgresql - Reporting Services - 连接字符串和参数

转载 作者:行者123 更新时间:2023-11-29 12:05:50 24 4
gpt4 key购买 nike

此处正确的查询是什么?

我想让“年”成为一个参数:

select distinct
p.id "pub_id"
from
publication "p", organisation_association "oa", organisation "o", localized_string_text "lst_org"
where
p.id = oa.publication_id
and oa.organisation_id = o.id
and o.name_id = lst_org.localized_string_id
and p.submission_year = ?
and exists (select 1
from
publication "p2", organisation_association "oa2", organisation "o2"
where
p2.id = p.id
and p2.id = oa2.publication_id
and oa2.organisation_id = o2.id
and o2.period_end_date < date ? + '-01-01')

但是最后一行的连接会产生语法错误。

最佳答案

如果参数作为年份字符串传递:

and o2.period_end_date < date (? || '-01-01'))

如果是日期:

and o2.period_end_date < date_trunc('year', ?)

如果是年份数:

and o2.period_end_date < date (?::text || '-01-01'))

关于postgresql - Reporting Services - 连接字符串和参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17442072/

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