Closed bletera closed 10 months ago
SELECT query is processed in this order.
Therefore, column aliases specified in the SELECT clause cannot be used in clauses processed before it.
Thank you for your reply. Then how to I do a SELECT for a file that does not have a field name and I need to group a field by a calculated field? Is there a solution?
The easiest way is to use a subquery.
SELECT t.Vare,
COUNT(t.Vare) AS Count
FROM (
SELECT SUBSTR(c3, INSTR(c3, "#") + 1) AS Vare
FROM `status.log`
) t
GROUP BY t.Vare
When I try your query, get this error syntax error: unexpected token "Count".
When run standalone inner query, all it`s OK, but with whole query, I get error.
Sorry, count
is a reserved word and must be enclosed.
SELECT t.Vare,
COUNT(t.Vare) AS `Count`
FROM (
SELECT SUBSTR(c3, INSTR(c3, "#") + 1) AS Vare
FROM `status.log`
) t
GROUP BY t.Vare
Thank you. Query is working.
If I use a computed field with any function and alias in SELECT, and use this alias in a GROUP BY clause, this query evaluates with an error that there is no field with that name (alias).
Example SELECT SUBSTR(
c3
, INSTR(c3
, "#") + 1) ASVare
, COUNT(Vare
) ASCount
FROMC:\Program Files (x86)\server\Logs\status.log
GROUP BYVare
;Error: query.sql [L:7 C:2] field
Vare
does not exist