[英]Alias with Order by
I have a query : 我有一个查询:
SELECT distinct(a0.ID,a0.str)
from sev_modul_4_type1 as a0
where ((lower(a0.str) LIKE '%а%'))
And i want to order it by str but if do it like that 我想按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
I get an error: 我收到一个错误:
ERROR: column "str" does not exist
LINE 1: ...s a0 where ((lower(a0.str) LIKE '%а%'))) x order by str desc
^
And even if i use sev_modul_4_type1.str
, a0.str
etc. 即使我使用sev_modul_4_type1.str
, a0.str
等。
How can i do it right? 我该怎么办?
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) 我也尝试order by 2 desc
但它给了我相同的错误,只能order by 1 desc
排序(按ID排序)
Try this way 试试这个
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
Try removing the parenthesis from distinct and then using the alias in your ORDER BY clause. 尝试从括号中除去括号,然后在ORDER BY子句中使用别名。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.