别名顺序 [英] Alias with Order by

查看:78
本文介绍了别名顺序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个查询:

SELECT distinct(a0.ID,a0.str)  
from sev_modul_4_type1 as a0 
where ((lower(a0.str) LIKE '%а%'))

我想按str排序,但如果这样做

And i want to order it by str but if do it like that

select * from (
   SELECT distinct(a0.ID,a0.str)  
   from sev_modul_4_type1 as a0 
   where ((lower(a0.str) LIKE '%а%'))
) x order by str desc

我收到一个错误:

ERROR:  column "str" does not exist
LINE 1: ...s a0 where ((lower(a0.str) LIKE '%а%'))) x order by str desc
                                                         ^

排序,即使我使用 sev_modul_4_type1.str a0.str 等。

And even if i use sev_modul_4_type1.str, a0.str etc.

我该怎么做是吗?

我还尝试了按2 desc的订单,但是它给了我相同的错误,并且只能 order b y 1 desc (按ID排序)

I also tried order by 2 desc but it gives me the same error and it's ok only order by 1 desc (which sorts by id)

推荐答案

select * from (
   SELECT distinct a0.ID, a0.str  
   from sev_modul_4_type1 as a0 
   where ((lower(a0.str) LIKE '%а%'))
) x order by x.str desc

尝试从括号中删除括号,然后在您的计算机中使用别名ORDER BY子句。

Try removing the parenthesis from distinct and then using the alias in your ORDER BY clause.

这篇关于别名顺序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆