ALTER proc [dbo]. [Proc_getZhanDianShuJuData1]

@ stime varchar (200), - start time from

@ etime varchar (200), - to

@ start1 varchar (200) - Termination Time from,

@ end1 varchar (200) - to

as

declare @ dian1 decimal (18,2), @ dian2 decimal (18,2), @ liuliang1 decimal (18,2), @ liuliang2 decimal (18,2 )

set @ dian1 = (select sum (UsePower) from History where Testtime> = @ stime and Testtime <= @ etime group by StationName)

set @ dian2 = (select sum (UsePower) from History where Testtime> = @ start1 and Testtime <= @ end1 group by StationName)

set ; @ liuliang1 = (select sum (Alltotalrunning) from History where Testtime> = @ stime and Testtime <= @ etime group by StationName)

set @ liuliang2 = (select ; sum (Alltotalrunning) from History where Testtime> = @ start1 and Testtime <= @ end1 group by StationName)

select distinct Stationinfo.StationName as station name, @ dian1 as the starting power, @ dian2 as termination charge, @ liuliang1 as the starting cumulative flow, @ liuliang2 as termination cumulative flow,

@

[email protected] dian1 as electricity volume, @

[email protected] liuliang1 as water, Convert (decimal (18,2), (@

[email protected] dian1) / (@

[email protected] liuliang1)) as tons of water consumption from History, Stationinfo

where Testtime between @ stime and @ end1 and History.StationName = Stationinfo.Agreement group by Stationinfo.Agreement, Stationinfo.StationName

The above is what I wrote a stored procedure, I have added in a subquery group by not grouped query data. Then error: Subquery returned more than 1 value. When the subquery follows =,! =, <, <=,>,> = Or when the subquery is used as an expression, this situation is not allowed.