Does this MySQL Query have hidden gotchas?

I hope this is not a terribly dumb question. I notice that MySQL will allow me to return to the "Mnth" field in my group and ORDER. This does not apply to every db engine I've worked with. Can anyone argue that this is an OK approach?

SELECT DATE_FORMAT(FROM_UNIXTIME(`swauditlogs`.`dateline`),'%Y-%m') AS Mnth, Count(`swauditlogs`.`ticketid`) AS Count
FROM swauditlogs LEFT JOIN swtickets ON swauditlogs.ticketid = swtickets.ticketid
WHERE swauditlogs.actionmsg Like 'Ticket status changed from:%to: Closed'
GROUP BY Mnth
ORDER BY Mnth DESC
+3
source share
4 answers

Everything is fine. From http://dev.mysql.com/doc/refman/5.0/en/select.html :

A select_expr can be assigned an alias using AS alias_name. The alias is used as the name of the expression column and can be used in GROUP BY, ORDER BY, or HAVING clauses.

LIKE. , , LIKE ?

+3
+3

MySQL, , . , MySQL, .

, : : , , , , , -)

+1

IMHO, MySQL.

Standard SQL prohibits references to column aliases in a WHERE clause, but you can use an alias in GROUP BY, ORDER BY, or HAVING clauses to reference a column.

http://dev.mysql.com/doc/refman/5.0/en/problems-with-alias.html

+1
source

Source: https://habr.com/ru/post/1731381/


All Articles