SQL QUERY HELP,怎么做?

时间:2017-08-09 06:28:36

标签: mysql sql

SELECT * FROM tbl_subject WHERE SubjectName='MATH',SubjectStart LIKE '7:00 A.M',SubjectEnd LIKE '8:00 A.M'

HELP !!

SubjectStart和SubjectEnd是varchar

ERROR:

查询:

 Select * from tbl_subject   where SubjectName='MATH',  SubjectStart like '7:00 A.M',  SubjectEnd like '8:00 A.M'  LIMIT 0, 1000

错误代码: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 '
SubjectStart like '7:00 A.M',
SubjectEnd like '8:00 A.M'
LIMIT 0, 1000' at line 2

4 个答案:

答案 0 :(得分:3)

条件必须由ANDOR分隔,而不是由comman

分隔
Select * from tbl_subject   
where SubjectName='MATH' AND  SubjectStart = '7:00 A.M' AND  SubjectEnd = '8:00 A.M'  LIMIT 0, 1000

如果没有通配符,LIKE就没有任何意义。

什么数据类型是SubjectStartSubjectEnd?它看起来应该是您应该使用数据时间数据类型的时间戳

答案 1 :(得分:0)

问题在于:

SubjectName='MATH',SubjectStart LIKE '7:00 A.M',SubjectEnd

可以使用ANDOR组合多个条件,而不是使用逗号,,如:

SubjectName='MATH' OR SubjectStart LIKE '7:00 A.M' OR SubjectEnd
SubjectName='MATH' AND SubjectStart LIKE '7:00 A.M' AND SubjectEnd

答案 2 :(得分:0)

您的查询应该是

SELECT * FROM tbl_subject WHERE SubjectName='MATH' and ( SubjectStart LIKE '7:00 A.M' or SubjectEnd LIKE '8:00 A.M')

答案 3 :(得分:0)

问题在于您需要查看的where子句语法:

Select * from tbl_subject   
where SubjectName='MATH' AND  SubjectStart like '7:00 A.M' 
 AND  SubjectEnd like '8:00 A.M'  LIMIT 0, 1000