簡體   English   中英

錯誤:“ and”處或附近的語法錯誤

[英]ERROR: syntax error at or near “and”

我有這樣的查詢。

select 
  ad.escore,
  ad.mscore,
  round(sum(ps.cnt) / sum(n.cnt) * 100,1) as percent
from 
(
  select 
    account_no,
    -- 602 becomes '595-604'
    to_char(trunc(empirica_score - 5, -1) + 5, '9999') || '-' || to_char(trunc(empirica_score - 5, -1) + 14, '9999') as escore,
    -- 97 becomes '76-100'. Change the expression to group differently.
    cast(((mfin_score - 1) / 25) * 25 + 1 as text) || '-' || cast(((mfin_score - 1) / 25) * 25 + 25 as text) as mscore
  from account_details
) ad
join 
(
  select custno, count(*) as cnt
  from paysoft_results 
  where result = 'Successful' 
  and resultdate >= '13/08/2014'     <------- HERE
  and resultdate <= '12/19/2014'     <------- HERE
  group by custno
) ps on ps.custno = ad.account_no
join 
(
  select customer_code, count(distinct start_date) as cnt
  from naedo 
  and start_date >= '13/08/2014'      <------- HERE
  and start_date <= '12/19/2014'      <------- HERE
  group by customer_code
) n on n.customer_code = ad.account_no
group by ad.escore, ad.mscore;

如果我沒有像上面那樣安裝日期,它將非常完美。

如果我確實輸入日期,則會收到錯誤ERROR: syntax error at or near "and"

有什么想法嗎?

更新

好吧,我想我現在可以問一個問題,所以我可以補充一下這個問題。

ERROR: date/time field value out of range: "13/08/2014"

我查詢中的日期比較。 正確的方法是什么?

好吧, 一點行不通:

select customer_code, count(distinct start_date) as cnt
from naedo 
and start_date >= '13/08/2014'      <------- HERE
and start_date <= '12/19/2014'      <------- HERE
group by ...

因為where子句必須以where而不是and開頭。 否則,我們都將其稱為and子句:-)

它必須是:

select customer_code, count(distinct start_date) as cnt
from naedo 
where start_date >= '13/08/2014'
  and start_date <= '12/19/2014'
group by ...

您在HERE標記的另一位(第二段,第一個join子句)看起來不錯,它應該可以正常工作。


順便說一句,您的日期中至少有一個格式不正確。 細分:

and start_date >= '13/08/2014'
and start_date <= '12/19/2014'

要么日期是十一月8 ,要么是十二月12 ,我什至不知道十九的拉丁字母前綴(或基於已經不合實際的月份為十七)。

您需要確定您的數據庫支持mm/dd/yyyy還是dd/mm/yyyy一個 ,然后再堅持使用那個

鑒於您對update的質疑指出它在抱怨13/08/2014 ,您可能會發現它應該以mm/dd/yyyy格式寫為08/13/2014年8 mm/dd/yyyy

    select customer_code, count(distinct start_date) as cnt
      from naedo 
      Where start_date >= '13/08/2014'      <------- HERE
      and start_date <= '12/19/2014'      <------- HERE
      group by customer_code

查詢中缺少“哪里”:

"    select customer_code, count(distinct start_date) as cnt
      from naedo where
      start_date >= '13/08/2014'      <------- HERE"
"
============================
select 
      ad.escore,
      ad.mscore,
      round(sum(ps.cnt) / sum(n.cnt) * 100,1) as percent
    from 
    (
      select 
        account_no,
        -- 602 becomes '595-604'
        to_char(trunc(empirica_score - 5, -1) + 5, '9999') || '-' || to_char(trunc(empirica_score - 5, -1) + 14, '9999') as escore,
        -- 97 becomes '76-100'. Change the expression to group differently.
        cast(((mfin_score - 1) / 25) * 25 + 1 as text) || '-' || cast(((mfin_score - 1) / 25) * 25 + 25 as text) as mscore
      from account_details
    ) ad
    join 
    (
      select custno, count(*) as cnt
      from paysoft_results 
      where result = 'Successful' 
      and resultdate >= '13/08/2014'     <------- HERE
      and resultdate <= '12/19/2014'     <------- HERE
      group by custno
    ) ps on ps.custno = ad.account_no
    join 
    (
      select customer_code, count(distinct start_date) as cnt
      from naedo where
      start_date >= '13/08/2014'      <------- HERE
      and start_date <= '12/19/2014'      <------- HERE
      group by customer_code
    ) n on n.customer_code = ad.account_no
    group by ad.escore, ad.mscore;

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM