I'm running a cron daily, and keep records saved in a table. Wrote a query to see the daily progress of the users, but facing an issue.
I have local and production environments with separate data bases.
SELECT *, LAG(value) OVER(PARTITION BY node_id ORDER BY created_at) old_value
FROM ledger WHERE ledger_type_id = 1
This is the part of the query that is failing. I think the db driver has something to do it. The query was working on the prod data base, from my SQL client, but I just noticed that it is running MySQL 8, and the prod db is 10.3.16-MariaDB.
Tried the same query on my local data base - MySQL 5.7, and got this error:
[2019-08-06 16:12:47] [42000][1064] You have an error in your SQL syntax;
check the manual that corresponds to your MySQL server version for the right syntax
to use near '(PARTITION BY node_id ORDER BY created_at) AS old_value
After this I did 2 more tests:
Ran the query on the prod server it self, via phpmyadmin, and the server complete died, for a few minutes.
Ran the query from my code on the prod environment (laravel 5.8):
DB::select(DB::raw('
SELECT *, LAG(value) OVER(
PARTITION BY node_id ORDER BY created_at
) old_value
FROM ledger WHERE ledger_type_id = 1
'))
and got this in my laravel log:
production.ERROR: SQLSTATE[42000]: Syntax error or access violation:
1140 Mixing of GROUP columns (MIN(),MAX(),COUNT(),...) with no GROUP columns is
illegal if there is no GROUP BY clause
Am I doing something incorrect?
Related
With MySQL 5 this query worked without any issue:
SELECT 1+COUNT(*) AS rank
FROM userpoints
WHERE points > COALESCE((SELECT points FROM userpoints WHERE userid=(SELECT userid FROM users WHERE handle='abc123' LIMIT 1)), 0)
With MySQL 8.0.23 it throws an error:
MySQL query error 1064: You have an error in your SQL syntax
Is it not allowed to "embed" SELECTs into other SELECTs anymore? See the userid=(SELECT... part.
Or is it a problem with COALESCE?
I have query in my structure trying run in PHPMYADMIN. I am trying to run CUBE query for OLAP operation, this is my query :
SELECT QUARTER, REGION, SUM(SALES)
FROM salestable
GROUP BY CUBE (QUARTER, REGION)
I have also tried this query :
SELECT salestable.QUARTER, salestable.REGION, SUM(salestable.SALES)
FROM salestable
GROUP BY CUBE (salestable.QUARTER, salestable.REGION)
but it showing this error :
#1064 - You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near '(QUARTER, REGION) LIMIT 0, 25' at line 3
I tried to open the page to check syntax but it shows page not found.
I don't think MySQL supports CUBE as a GROUP BY modifier, but you can use WITH ROLLUP:
SELECT st.QUARTER, st.REGION, SUM(st.SALES)
FROM salestable st
GROUP BY st.QUARTER, st.REGION WITH ROLLUP;
I have made a sql statement that works normal in a shared server. but since I migrated the database to a local one
it showing a #1064 - You have an error in your SQL syntax
INSERT INTO shops (shop_name, googleid, address, city, country, open_now, logogroup, idshopgroup, shop_group, image, website)
select '$shopname', '".$key["googleid"]."','$address','".$key["city"]."',
'".$key["country"]."', '".$key["open_now"]."','".$key["logo"]."','".$key["groupid"]."','$groupname','".$key["photo_reference"]."', '".$key["website"]."'
WHERE NOT EXISTS (
SELECT googleid FROM shops WHERE googleid = '".$key["googleid"]."'
) LIMIT 1;
I fixed the problem by adding a "from 'tablename'" before the "WHERE" clause
I know there is 100+ posts about it, but there is a information about time out etc, not about query...
MySQL Server: 5.7.17
MySQL Workbench: 6.3.8
Query:
SELECT transactionID, fromAccount,ToAccount, transactionDate, amount, type
FROM accounttransactions WHERE toAccount = '12345' #OR fromAccount = '12345'
Respond:
It works, but when I change my query and add(uncomment in this scenario) OR in WHERE statement then it Running for ~6s and looks like:
Error Code: 2013. Lost connection to MySQL server during query
This gives me strange error.
> Customer.where(:my_text_field => "05007062").first
> Customer Load (0.9ms) SELECT `customers`.* FROM `customers` WHERE `customers`.`my_text_field` = '05007062' LIMIT 1
ActiveRecord::StatementInvalid: Mysql2::Error: Invalid date: 2012-00-00 00:00:00: SELECT `customers`.* FROM `customers` WHERE `customers`.`my_text_field` = '05007062' LIMIT 1
...
Does anyone know why could that be? I don't see any date in the query. Also, this happens only in production and not on development machine (both running linux).
I'm using Rails 3.1.0 and mysql2 0.3.10
Sounds like you may have some corrupted data in one of the records on your prod server. Do you have some other code that creates records in the db - including a date?