[英]Alias with Order by
我有一个查询:
SELECT distinct(a0.ID,a0.str)
from sev_modul_4_type1 as a0
where ((lower(a0.str) LIKE '%а%'))
我想按str订购它,但是如果这样做的话
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
等。
我该怎么办?
我也尝试order by 2 desc
但它给了我相同的错误,只能order by 1 desc
排序(按ID排序)
试试这个
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
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子句中使用别名。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.