oraclesql中groupby后如何加入

2guxujil  于 2021-07-27  发布在  Java
关注(0)|答案(2)|浏览(283)

我有以下示例sql这个sql不起作用。
我想在分组后加入。我试图提取表作为 tran 然后我希望加入描述表 t2tran .

select *
from (  
    select count(t.code),t.code
    from  table t
    group by t.code
    order by count(t.code) desc ) as tran

left join code_description t2
on tran.code = t2.code

我犯了以下错误 ORA-00933: SQL command not properly ended 什么是错误的观点?我怎样才能修好它们?
谢谢

insrf1ej

insrf1ej1#

请试试这个:

select *
from (  
    select count(t.code) as kol,t.code
    from  table t
    group by t.code
     ) as tran

left join code_description t2
on tran.code = t2.code
order by tran.kol desc
wpx232ag

wpx232ag2#

使用 order by 子查询外

select 
  *
from 
  (  
    select 
      count(t.code) as total,
      t.code
    from  table t
    group by t.code
  ) as tran

left join code_description t2
on tran.code = t2.code
order by tran.total desc

相关问题