存储过程:MySQL,错误

时间:2018-03-30 05:12:34

标签: mysql stored-procedures

无法选择id字段INTO @testId表,显示错误代码。

代码

SELECT id INTO @testId, (3959 * ACOS (COS ( RADIANS(deviceLat ) ) * COS( RADIANS(`latitude`) )* 
COS( RADIANS(`longitude` ) - RADIANS(deviceLong) )+ SIN ( RADIANS(deviceLat) )* 
SIN( RADIANS(`latitude` )))) AS dist INTO @distance FROM route_waypoints 
GROUP BY route_ID = @routeID AND (route_waypoints.type =  'PICK' OR 
route_waypoints.type = 'CAMPUS') HAVING dist < 250  ORDER BY dist ASC LIMIT 1;

1 个答案:

答案 0 :(得分:0)

试试这个......

  // Declare variables with datatype and size
    DECLARE @testId int, @distance varchar(500 

    // set value of the selected column to that variable by = operator.
    SELECT @testId = id, 
           @distance = (3959 * ACOS (COS ( RADIANS(deviceLat ) ) * COS( RADIANS(`latitude`) )* 
                        COS( RADIANS(`longitude` ) - RADIANS(deviceLong) )+ SIN ( RADIANS(deviceLat) )* 
                        SIN( RADIANS(`latitude` ))))
            FROM route_waypoints 
            GROUP BY route_ID = @routeID AND (route_waypoints.type =  'PICK' 
            OR route_waypoints.type = 'CAMPUS') HAVING dist < 250  
            ORDER BY dist ASC LIMIT 1;    

   // Print    
   SELECT @testId, @distance