当前位置: 代码迷 >> Sql Server >> mysql 存储过程 在线 急 求解答!解决方法
  详细解决方案

mysql 存储过程 在线 急 求解答!解决方法

热度:368   发布时间:2016-04-24 20:07:09.0
mysql 存储过程 在线 急急急 求解答!!!
这是我写的存储过程,
set onepickUpVehicle = '京AG7614'的时候就会报错
ERROR 1242 (21000): Subquery returns more than 1 row
但是当set onepickUpVehicle = '京AD4977' 就没有问题,程序能正常执行。这是为什么???

BEGIN
/*起始时间|上车时间*/
DECLARE startime varchar(20);
/*结束时间|下车时间*/
DECLARE endtime varchar(20) ;
/*上车站号*/
DECLARE upnum int(11) ;
/*循环判断条件*/
DECLARE b varchar(10);
/*避免死循环,设置循环次数*/
DECLARE i int(11) ;
/*当前站号*/
DECLARE starnum int(11);
/*下一站站号*/
DECLARE endnum int(11);
/*最大站号*/
DECLARE maxnum int(11);
/*判断站号顺序*/
DECLARE checknum varchar(20);
/*统计人数*/
DECLARE peopels int(11);
/*上车人数*/
DECLARE uppeople int(11);
/*下车人数*/
DECLARE getpeople int(11);
/*临时变量*/
DECLARE num int(11);
DECLARE num1 int(11);
DECLARE num2 int(11);
DECLARE num3 int(11);
DECLARE drivernum int(11) ;
DECLARE drivermax int(11) ;
DECLARE driverone varchar(20) ;
DECLARE uptime varchar(20) ;
DECLARE gettime varchar(20) ;
DECLARE onepickUpVehicle varchar(20) ;
DECLARE onecarUpnum int(11);
DECLARE onetransactionType  varchar(20);
DECLARE onetransactionDate  varchar(20);

set names utf8;
set onepickUpVehicle = '京AG7614';
set onetransactionType = '一般消费';
set onetransactionDate = '20131015';

CREATE TEMPORARY TABLE IF NOT EXISTS carpeople (
pickUpVehicle varchar(20)  not null,
        pickUpTime varchar(20)  not null,
pickUpStationNum  int(11)  not null,
peoplenum int(11)  not null
);
CREATE TEMPORARY TABLE IF NOT EXISTS carerror (
pickUpVehicle varchar(20)  not null,
pickUpTime varchar(20)  not null,
pickUpStationNum  int(11)  not null,
peoplenum int(11)  not null
);


CREATE TEMPORARY TABLE IF NOT EXISTS onetime (
id int(11) not null AUTO_INCREMENT,
pickUpTime varchar(20)  not null,
gettime varchar(20)  not null,
lorr varchar(20) not null,
PRIMARY KEY (`id`)
);

CREATE TEMPORARY TABLE IF NOT EXISTS oneday (
driver varchar(8) not null,
pickUpTime varchar(20)   not null,
pickUpVehicle varchar(20)   not null,
pickUpStationNum  int(11)   not null,
getOffStationNum int(11)   not null ,
revenueAmount float(5)  not null
);

CREATE TEMPORARY TABLE IF NOT EXISTS onedriver (
driver varchar(20)
);

CREATE TEMPORARY TABLE IF NOT EXISTS onecarUp(
driver varchar(8) not null,
pickUpTime varchar(20)  not null,
pickUpVehicle varchar(20)  not null,
pickUpStationNum  int(11)  not null,
getOffStationNum int(11)  not null,
revenueAmount float(5) not null
);



CREATE TEMPORARY TABLE IF NOT EXISTS people(
id int(11) not null ,
pickUpTime varchar(20)  not null,
getOffTime varchar(20)  not null,
starnum int(11) not null
);



insert into oneday (
select pgtraffic.card.driver,pgtraffic.card.pickUpTime,pgtraffic.card.pickUpVehicle,pgtraffic.card.pickUpStationNum,pgtraffic.card.getOffStationNum,pgtraffic.card.revenueAmount
from pgtraffic.card
where pgtraffic.card.transactionDate='20131015'
order by pgtraffic.card.pickUpTime
);



insert into onecarUp (
select o.driver,o.pickUpTime,o.pickUpVehicle,o.pickUpStationNum,o.getOffStationNum,o.revenueAmount
from oneday as o
where o.pickUpVehicle=onepickUpVehicle
);


insert into onedriver (
select o.driver
from onecarUp as o
group by o.driver
);


set drivermax = (select count(o.driver) from onedriver as o);
set drivernum = 1;

WHILE drivernum <= drivermax  DO

set driverone = (select o.driver from onedriver as o limit 0,1);

set onecarUpnum = (
select count(o.getOffStationNum)
from onecarUp as o
where o.revenueAmount != 1
and o.driver = driverone
and o.pickUpStationNum != o.getOffStationNum
);

if onecarUpnum is not null then



/*获取最大站号*/
set maxnum = (select o.pickUpStationNum from onecarUp as o order by o.pickUpStationNum desc limit 0,1);
  相关解决方案