【问题标题】:Why Count function is not working on this sub query?为什么 Count 函数不适用于此子查询?
【发布时间】:2015-05-30 04:43:21
【问题描述】:

这个:

输出如下:

现在我想对上表应用计数函数,因为我执行了以下查询。

select count(date1) from (
select date1 from tmp where 
current_date > date1
);

得到了这个错误:

错误代码 20000,SQL 状态 42X01:语法错误:遇到“” 在第 4 行第 1 列。

注意:我使用的是 Java DB

【问题讨论】:

  • @JoaozitoPolo 仍然遇到同样的错误

标签: sql derby javadb


【解决方案1】:

子查询通常需要一个别名,试试

 select count(date1) from (
   select date1 from tmp where 
   current_date > date1
 ) a ;

【讨论】:

    【解决方案2】:

    我不知道 JavaDb,但请尝试给嵌套的 select 语句一个别名:

    Select count(*) cnt from (select date1 from tmp where current_date > date1) a

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-12-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-10-15
      • 2020-12-27
      • 2019-12-05
      • 2020-05-12
      相关资源
      最近更新 更多