我在PostgreSQL上写了以下命令:
create table Daily_Winners as (
select d.* from
(
select row_number() over(partition by "request_date",
"revised_circle"
order by "earned_score" desc,
"count_of_attempts" asc) rn,
*
from
(
select a.*,b.count_of_attempts, last_que_attempt
from
(
select msisdn, revised_circle,
to_date(left(a.request_date,10),'yyyy-mm-dd')request_date,
sum(cast(score as numeric(10,0))) Earned_Score
from Airtel_season13_circles_final a
where upper(a.ans_type)='CA'
group by Revised_Circle,
to_date(left(a.request_date,10),'yyyy-mm-dd'),
msisdn
)a
join
(
select distinct revised_circle,
to_date(left(a.request_date,10),'yyyy-mm-dd')request_date,
msisdn,
count(distinct transaction_id) count_of_attempts,
max(to_timestamp(request_date, 'YYYY-MM-DD HH24:MI:SS')::timestamp without time zone)last_que_attempt
from Airtel_season13_circles_final a
group by revised_circle,
to_date(left(a.request_date,10),'yyyy-mm-dd'),
msisdn
)b
on a.msisdn=b.msisdn and a.revised_circle=b.revised_circle
and a.request_date=b.request_date
)c
)d
where d.rn<=20)
执行此操作时出现以下错误:
错误:“yyyy”的无效值“requ”
细节:价值必须是 整数。
任何人都可以帮忙吗?任何建议将不胜感激。谢谢。
答案 0 :(得分:0)
您的字段request_date
似乎是一个文本,并且对于至少一行,最左边的4个字符不是4个数字而是字符串REQU。
当您尝试将字符串转换为日期时,您指定格式,并且没有与您指定的格式兼容的值
- &GT;您必须过滤不良数据,或者修改字符串精确度,甚至更好,将日期保存在date
字段中。