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

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.

Related

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?

last query result

SELECT sma_quotes.customer as name,
sma_quotes.date as date,
sma_quotes.selecttype as type,
sma_quotes.biller_id as bl_id,
sma_quotes.volume as volume,
sma_quotes.containernumber as cn_no,
sma_quotes.grand_total as total,
sma_sales.paid as paid
FROM sma_quotes
JOIN sma_sales ON sma_sales.quote_id = sma_quotes.id
WHERE name IS 'Everbest Foods'
Error
SQL query: Documentation
MySQL said: Documentation
#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 ''Everbest Foods' LIMIT 0, 25' at line 1
There is no LIMIT in your query, so the error message is suspicious.
However, you want =, not IS:
WHERE sma_quotes.customer = 'Everbest Foods'

ERROR 1064 (42000) works on WebSQL but not on 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.

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`)