ERROR 1064 (42000) works on WebSQL but not on MySQL - mysql

When using mysql to run this query,
select country_code, Avg(freq) as frequency
from
(
select t1.country_code, t1.freq
from avg_call country_code_final t1
union all
select t2.country_code, t2.freq
from calls_at_one xx_country_code_frequency t2
)
group by country_code;
I received an
ERROR 1064 (42000): 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 '
select t1.country_code, t1.freq
from avg_call country_code_final t1
union all
select t2.country_code, t2.freq
from calls_at_one xx_country_code_frequency t2
)
group by country_code;'`
I tried running this on WebSQL it work.

Related

Why does this query break when I include a second WHERE condition?

The query is
SELECT account_id, type_id, client_id, avail_balance
FROM accounts
WHERE open_emp_id
IN (SELECT emp_id
FROM employee
WHERE (branch_id = 1111) AND (job_id NOT LIKE ‘HD%’);
Without the second WHERE condition, the query works fine. With that condition, I get
ERROR 1064 (42000): 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 '%’))' at line 1

sql query error when using "with" I got an an error like 1064 syntax error

with firstcte (first_name,active) as(
select first_name,active from customer)
select * from firstcte
Error Code: 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 'firstcte (first_name,active) as(
select first_name,active from customer)
select ' at line 1 0.000 sec

Getting syntax error using WITH (Common Table Expressions) in mysql 8

I am using mysql 8.0.21. I am trying to execute this statement:
WITH t
AS (SELECT h.store_hsh,
Avg(s.sales) AS SALES_AVG,
Avg(s.customers) AS CSTMR_AVG
FROM sat_day_facts s
INNER JOIN link_day l
ON s.link_day_hsh = l.link_day_hsh
INNER JOIN hub_store h
ON h.store_hsh = l.store_hsh
GROUP BY h.store_hsh)
SELECT t.store_hsh,
Now() AS LOAD_DATETIME,
Now() AS LOAD_END_DATETIME,
t.sales_avg,
t.cstmr_avg,
(SELECT 1 + Count(*)
FROM t t1
WHERE t1.sales_avg > t.sales_avg) AS SALES_RANK;
but I keep having this error
ProgrammingError: 1064 (42000): 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 'WITH t as (select h.STORE_HSH, AVG(s.SALES) as SALES_AVG , AVG(s.CUSTOMERS) as' at line 1
I checked the manual of SQL but still don't understand what is going wrong.
Does anyone could help?

mysql -- ERROR 1064 (42000): .... near '(PARTITION BY t1.DIGEST)

I tried to execute this query in ubuntu / mysql:
SELECT t1.SCHEMA_NAME, CONCAT(ROUND(BUCKET_QUANTILE*100,2),"% under ",
BUCKET_TIMER_HIGH/1000000000," milliseconds") fact,
LEFT(QUERY_SAMPLE_TEXT,64) as QUERY_SAMPLE, t1.DIGEST,
COUNT(t1.DIGEST)
OVER(PARTITION BY t1.DIGEST) as TOT
FROM events_statements_histogram_by_digest t1
JOIN events_statements_summary_by_digest t2
ON t2.DIGEST = t1.DIGEST
WHERE COUNT_BUCKET >1
ORDER BY t1.DIGEST, BUCKET_TIMER_HIGH DESC
LIMIT 10\G
and the result :
ERROR 1064 (42000): 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 t1.DIGEST) as TOT FROM events_statements_histogram_by_digest t1 JO'
at line 1
I have not found a way to correct that query. Please help. thanks.

How to convert a MySQL query to Laravel 5?

i want to convert this mysql query to laravel. please advice
below is mysql code i tried
select
user_id,time_sheet_id,role_id,
TIME_FORMAT(SEC_TO_TIME(sum(TIME_TO_SEC(TIMEDIFF( shift_end_time, shift_start_time)))), "%h:%i") AS diff
FROM
shifts
group by
time_sheet_id
this is my laravel code, but its giving syntax errors
$findTotalhours = DB::table('shifts')
->select(DB::raw('user_id, time_sheet_id,role_id TIME_FORMAT(SEC_TO_TIME(sum(TIME_TO_SEC(TIMEDIFF( shift_end_time, shift_start_time)))), "%h:%i") AS diff'))
->groupBy('time_sheet_id')
->get();
UPDATE
SQLSTATE[42000]: Syntax error or access violation: 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 '(SEC_TO_TIME(sum(TIME_TO_SEC(TIMEDIFF( shift_end_time, shift_start_time)))), "%h' at line 1 (SQL: select user_id, time_sheet_id,role_id TIME_FORMAT(SEC_TO_TIME(sum(TIME_TO_SEC(TIMEDIFF( shift_end_time, shift_start_time)))), "%h:%i") AS diff from `shifts` group by `time_sheet_id`)