大家好,我在查询条件中尝试使用@year文本时遇到问题
我用过:
SET @year := "2013";
SELECT count(*) as July FROM sinisters
WHERE date BETWEEN "@year-07-01" AND "@year-07-31" )
我一无所获。
我也试过了:
SET @year := "2013";
SELECT year(date) as July FROM sinisters
WHERE date BETWEEN "'{@year}'-07-01" AND "'{@year}'-07-31" )
我想像2013年一样使用@year。
请有人帮我这个吗?
答案 0 :(得分:2)
使用CONCAT函数连接变量和固定文本:
SELECT count(*) as July
FROM sinisters
WHERE date BETWEEN CONCAT(@year, "-07-01") AND CONCAT(@year, "-07-31")