-1

我在mysql中创建了一个程序,但是程序中什么都不能选择,这是怎么回事?

delimiter //
create procedure getLineStasticFreightList(in start int(4),in row int(4),in stationIDD varchar(4),in dateStart datetime,in dateEnd datetime)
BEGIN
DROP VIEW IF EXISTS rqusg_lineStasticFreightUser;
CREATE VIEW rqusg_lineStasticFreightUser AS 
SELECT a.id, c.stationName as station,b.name as track,sum(a.dddwTime) AS zgdddwsj, sum(a.ddzxTime) AS zgddzxsj, sum(a.zxzyTime) AS zgzxzysj, sum(a.ddzngyTime) AS zgddzngysj, sum(a.hcddqsTime) AS zgddqssj
FROM rqusg_line_yard a
 join rqusg_line_tracks b
   on a.track = b.id
 join rqusg_line_stations c
   on a.stationID =  c.stationID
WHERE a.stationID = 'stationIDD' and a.arriveTime >= 'dateStart'  and a.clczTime <= 'dateEnd'
group by a.track
union
select a.id,c.stationName as station,b.name as track,sum(a.dddwTime) as zgdddwsj,sum(a.ddzxTime) as zgddzxsj,sum(a.zxzyTime) as zgzxzysj,sum(a.ddzngyTime) as zgddzngysj,sum(a.hcddqsTime) as zgddqssj
from rqusg_line_yard a
 join rqusg_line_tracks b
   on a.track = b.id
 join rqusg_line_stations c
   on a.stationID =  c.stationID
WHERE a.stationID = 'stationIDD' and a.arriveTime >= 'dateStart' and a.clczTime <= 'dateEnd'
group by a.track;
select * from rqusg_lineStasticFreightUser LIMIT start,row;
END
//

在我的程序中,我创建了一个视图并从视图中选择了详细信息,但我什么也不能选择。我认为参数中有问题,但我不确定。有人可以帮我吗?

4

2 回答 2

0

您不应该在参数变量周围加上引号:

WHERE a.stationID = stationIDD and a.arriveTime >= dateStart  and a.clczTime <= dateEnd

顺便说一句,您的 UNION 中的两个子查询是相同的。为什么你有两次相同的查询?

于 2013-07-16T08:12:57.990 回答
0

您可能会在此行出现错误,WHERE a.stationID = 'stationIDD' and a.arriveTime >= 'dateStart' and a.clczTime <= 'dateEnd'因为您将单引号括在变量周围,该变量将其转换为常量字符串而不是变量。因此将其更改为

`WHERE a.stationID = stationIDD and a.arriveTime >= dateStart  and a.clczTime <=dateEnd`
于 2013-07-16T08:17:58.777 回答