error in mysql while featching interval data why? - mysql

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');

Related

filter date column mysql

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 'where paid_date between" January1,2021" and "Getdate()"' at line 5. Can someone help me fix my SQL?
select DATEDIFF(paid_date, cart_shipped_date) Days_till_paid, stat_completed_carts.*
from stat_completed_carts
where billing_method_id="30"
where paid_date between" January1,2021" and "Getdate()";

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'

in mysql where command not work

Hi when i call this query for select this work good and make output
select SUBSTR(img_address1,LOCATE('/',img_address2)+1,36)fROM content
but when i make this query this make a error
SELECT id from content WHERE ((SUBSTR(img_address2,LOCATE('/',img_address2)+1,5) LIKE'salam')
and this make error too
SELECT id from content WHERE ((SUBSTR(img_address2,LOCATE('/',img_address2)+1,5) = 'salam')
and my error is :
SELECT id from content WHERE ((SUBSTR(img_address2,LOCATE('/',img_address2)+1,5) = 'salam') LIMIT 0, 25
MySQL said: Documentation
#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 'LIMIT 0, 25' at line 1
There is an extra open bracket ( before SUBSTR. Removing it will fix the error.
SELECT id from content WHERE (SUBSTR(img_address2,LOCATE('/',img_address2)+1,5) = 'salam') LIMIT 0, 25

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

What is the problem with this mysql query

select count (*) from sales_order where date_format
(created_at,'%Y-%m-%d') >=
'2009-11-02' and date_format(created_at,'%Y-%m-%d')
<= '2010-12-08' and customer_id in
(14,1113,1115,1117,1132,1312,1345);
it gave me 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 '*) from sales_order where
date_format(created_at,'%Y-%m-%d') >= '2009-11-02' and' at line 1
Please let me know where is the problem
No space allow for count (*)
count(*)
The issue is with the space after COUNT. Do not use a space here. See this MySQL bug: Bug #2664 An extra space after Count in a Count(distinct... statement fails