I have the following SQL query:
SELECT SUM(tmp.mval), tmp.timekey FROM
(SELECT teghamas,
MAX(arzheq) as mval,
ceil(UNIX_TIMESTAMP(zhamanak)/(60 * 60)) AS timekey
FROM `masnakcutyun`
LEFT JOIN teghkentron ON `masnakcutyun`.`teghKentronId`=`teghkentron`.`teghKentronId`
WHERE teghkentron.hamaynq="London" group by timekey, teghkentron.teghamas)
AS tmp
GROUP BY tmp.timekey
It works fine in phpMyAdmin. But there's a warning there saying:
"This type of clause was previously parsed (near select)".
Can you guess what is the problem? The query can execute and return the expected results.
It seems to be a phpMyAdmin parser bug, see the issue on github, the query itself is valid.
MySQL allow write subquery in from
clause, but this is know issue, you can create view and use it :
CREATE VIEW viewname AS (SELECT teghamas,
MAX(arzheq) as mval,
ceil(UNIX_TIMESTAMP(zhamanak)/(60 * 60)) AS timekey
FROM `masnakcutyun`
LEFT JOIN teghkentron ON `masnakcutyun`.`teghKentronId`=`teghkentron`.`teghKentronId`
WHERE teghkentron.hamaynq="London" group by timekey, teghkentron.teghamas) ;
SELECT SUM(mval) as MySum, timekey
FROM viewname
GROUP BY timekey
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With