How to convert a MySQL query to Laravel 5? - mysql

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

Related

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'

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.

error in mysql while featching interval data why?

i did this in mysql
Select max(bid) FROM data WHERE realtime BETWEEN (2017-05-11 11:29:00) AND (2017-05-11 11:30:00);
i show error as
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 '11:29:00) AND (2017-05-11 11:30:00) LIMIT 0, 25' at line 1
You should put the dates in single quotes
Select max(bid) FROM data WHERE realtime BETWEEN ('2017-05-11 11:29:00') AND ('2017-05-11 11:30:00');

MySQL syntax error when using sqlite3 query

I just wanted to switch from sqlite3 to using MySQL but I get errors in this query:
SELECT
metapp_notif.id,
name,
age,
place,
note,
metapp_notif.lat,
metapp_notif.longt,
haslatlong,
dati,
ntype,
grpm_id,
image,
send_id,
pro.latitude,
pro.longtitude,
metapp_notif.dati,
metapp_notif.activity
FROM (metapp_notif
join (metapp_profil
join metapp_userlocation
ON metapp_profil.user_id = metapp_userlocation.user_id) AS pro
ON metapp_notif.send_id = pro.user_id)
WHERE metapp_notif.rec_id =% d;
I'm getting this error:
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 'pro on metapp_notif.send_id=pro.user_id) where
metapp_notif.rec_id=2' at line 1
I was searching for differences between sqlite3 and mysql but can't figure out what is wrong.
Thanks in advance!
Try this syntax in Mysql
SELECT metapp_notif.id,
name,
age,
place,
note,
metapp_notif.lat,
metapp_notif.longt,
haslatlong,
dati,
ntype,
grpm_id,
image,
send_id,
latitude,
longtitude,
metapp_notif.dati,
metapp_notif.activity
FROM metapp_profil
join metapp_notif
ON metapp_notif.send_id = metapp_profil.user_id
join metapp_userlocation
ON metapp_profil.user_id = metapp_userlocation.user_id
WHERE metapp_notif.rec_id like '% d'; -- Not sure what you are trying to do here

My sql syntax error 1064 -can't find what is wrong

I go this error message when I run this query
SELECT name,state FROM customers WHERE state ‌IN ('CA','NC','NY')
Error
SQL query: Documentation
SELECT name, state
FROM customers
WHERE state ‌IN(
'CA', 'NC', 'NY'
)
LIMIT 0 , 30
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 '‌in ('CA','NC','NY') LIMIT 0, 30' at line 1
I has a look there http://dev.mysql.com/doc/refman/5.6/en/error-messages-server.html but I still can't find the reason why
Thank you
Remove the = after IN
SELECT name, state FROM customers
WHERE state ‌IN ('CA','NC','NY')
SELECT name,state FROM customers WHERE state ‌IN ('CA','NC','NY')
You can not use the '=' with an IN
I tried to copy your query and run it in MySQL
You have some strange "hidden" character before IN
If you delete it, then everything works fine