【问题标题】:SQL code error mismatched input 'from' expectingSQL 代码错误不匹配输入“来自”预期
【发布时间】:2019-02-23 05:26:03
【问题描述】:

您好,下面是我的 SQL 代码,它给了我错误,我不知道为什么。如果有人可以提供帮助。

select time_dif, count(time_dif) as count 
from 
(
select datediff(so_so_close_time,date_closed) as time_dif
from `mbg_service_prd`.`mds_service_orders_base_cdl`
inner join `mbg_service_prd`.`rnt_incident_detail_base_cdl`
on 
(srv_customer_phone = mobile_phone or srv_customer_email = email_address)
where (
(srv_customer_phone<>''or srv_customer_phone is not null)
or (srv_customer_email<>'' or srv_customer_email is not null) 
or (mobile_phone<>'' or mobile_phoneis not null) 
or (email_addressis<>'' or email_addressis not null) 
)
)
group by time_dif
order by time_dif

它给了我错误说: org.apache.spark.sql.catalyst.parser.ParseException: 不匹配的输入'来自'期望{,'WHERE','GROUP','ORDER','HAVING','LIMIT','LATERAL','WINDOW','UNION','EXCEPT','INTERSECT','SORT ', 'CLUSTER', 'DISTRIBUTE'}(第 3 行,位置 0)

【问题讨论】:

  • 您需要为子查询提供别名

标签: sql apache-spark parseexception


【解决方案1】:

试试下面的查询

select a.time_dif, count(a.time_dif) as time_dif_count 
from 
(
select datediff(day,so_so_close_time,date_closed) as time_dif
from mbg_service_prd.mds_service_orders_base_cdl
inner join mbg_service_prd.rnt_incident_detail_base_cdl
on 
(srv_customer_phone = mobile_phone or srv_customer_email = email_address)
where (
(srv_customer_phone <> '' or srv_customer_phone is not null)
or (srv_customer_email <> '' or srv_customer_email is not null) 
or (mobile_phone <> '' or mobile_phone is not null) 
or (email_address <> '' or email_address is not null) 
)
)a
group by a.time_dif
order by a.time_dif

【讨论】:

    【解决方案2】:

    datediff 函数有错误。我们在 datediff 中使用了三个参数,即 interval、date1、date2。 DATEDIFF(interval, date1, date2).

    【讨论】:

      猜你喜欢
      • 2019-11-02
      • 1970-01-01
      • 2023-04-08
      • 2021-07-24
      • 1970-01-01
      • 1970-01-01
      • 2022-01-05
      • 1970-01-01
      • 2021-01-29
      相关资源
      最近更新 更多