2011-08-31 68 views
-1

这个查询:SUBSTR对SQL查询

SELECT substr(d.title,0,7) 
FROM orders_total d, orders o 
WHERE d.orders_id = o.orders_id 

给了我这个错误:

#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 '(d . title , '0' , '7') from orders_total d , orders o

它的工作原理没有SUBSTR,但我不能让它使用它。

回答

2

mySql documentation

For all forms of SUBSTRING(), the position of the first character in the string from which the substring is to be extracted is reckoned as 1.

所以,你必须改变0 1:

SELECT substr(d.title,1,7) 
FROM orders_total d, orders o 
WHERE d.orders_id = o.orders_id 
0
SELECT LEFT(d.title,7) FROM orders_total d, orders o WHERE d.orders_id = o.orders_id 
0

sbustr应子串,并开始对指数1,而不是0

据我所知,
+0

SUBSTR是SUBSTRING的同义词 – Cyclonecode