2017-07-20 7 views
0

する必要があります私は、PostgreSQL上で次のコマンドを書いた:YYYY」内のPostgreSQL-エラー; -Valueは、整数

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) 

これの実行は私に次のエラーを与えた:

ERROR: invalid value "requ" for "yyyy"
DETAIL: Value must be an integer.

ことができます誰でもしてくださいこれで助けてください?どんな提案も感謝します。ありがとうございました。

答えて

0

フィールドはrequest_dateのようですが、少なくとも1行は4つの左端の文字が4桁ではなく、REQUという文字列です。

日付に文字列を変換しようとすると、あなたは

を指定する形式を指定し、フォーマットと互換性のある値がない - あなたはあなたの悪いデータをフィルタしたり、文字列を修正する必要がありますいずれか>精度を上げる、またはそれ以上にするには、dateフィールドに日付を保存します。