HI我是mysql的新手并尝试通过存储过程更新表。我得到了#34;错过了分号错误。我尝试了所有内容,但我无法理解为什么会发生这种情况。
过程:
DROP PROCEDURE IF EXISTS abc;
use smartdata;
DELIMITER $$
CREATE PROCEDURE abc(IN datasourceId int)
begin
update DM_Sample_Search_Param_Disposition_Type set DM_Sample_Search_Param_Disposition_Type.Active = 0
From DM_Sample_Search_Param_Disposition_Type dm_ss_param_cl
left join DM_Sample_Search_Param dm_ss_param on dm_ss_param_cl.DM_Sample_Search_Param_id =dm_ss_param.DM_Sample_Search_Param_id
left join DM_Sample_Store dm_ss on dm_ss.DM_Sample_Store_Id=dm_ss_param.DM_Sample_Store_Id
where dm_ss.Datasource_Id=datasourceId;
end $$
DELIMITER //
近线以下的错误:
set DM_Sample_Search_Param_Disposition_Type.Active = 0
其中"活跃"在桌子上是tinyint。请帮忙
答案 0 :(得分:2)
MySQL使用与MSSQL不同的语法进行更新:update ... join .. set ... where ...
update DM_Sample_Search_Param_Disposition_Type dm_ss_param_cl
left join DM_Sample_Search_Param dm_ss_param on dm_ss_param_cl.DM_Sample_Search_Param_id =dm_ss_param.DM_Sample_Search_Param_id
left join DM_Sample_Store dm_ss on dm_ss.DM_Sample_Store_Id=dm_ss_param.DM_Sample_Store_Id
set DM_Sample_Search_Param_Disposition_Type.Active = 0
where dm_ss.Datasource_Id=datasourceId;
答案 1 :(得分:1)
错误的连接表sintax
/**
* Find the amount of points each boat in the race should have
*
* This method will assign points and, in the event of a tie,
* average them.
*
* @param $results
*
* @return array
*/
public function race_points($results)
{
$points = 0;
$results_with_points = array();
//assign incremental amounts of points to each boat
foreach ($results AS $result) {
//increment points by one for each position
$points++;
$result->points = $points;
//add result back to array;
$results_with_points[] = $result;
}
$results_with_points = $this->break_race_ties($results_with_points);
return $results_with_points;
}
/**
* Find any ties and average their points
*
* @param $results
*
* @return mixed
*/
protected function break_race_ties($results)
{
$ties = $this->find_race_ties($results);
if (!empty($ties)) {
//looks like there are tied results, average the points and assign them
foreach ($ties AS $tie) {
$points = $this->average_array_values($tie['points']);
foreach ($tie['id'] AS $id) {
$results[ $id ]->points = $points;
}
}
}
return $results;
}
/**
* Determine if any ties exist and get some information about them
*
* Finds any existing ties in the array of results and gets,
* their element id and the points of each tying boat.
*
* @param $results
*
* @return array
*/
protected function find_race_ties($results)
{
$previous_id = NULL;
$previous_points = NULL;
$previous_time = NULL;
$ties = array();
foreach ($results AS $id => $result) {
if ($previous_time === $result->lap_time) {
// Create empty array if required, so we don't push to NULL
if (!isset($ties[ $previous_time ])) {
$ties[ $previous_time ]['points'] = array();
$ties[ $previous_time ]['id'] = array();
}
// Add each individual value to the array containing duplicates.
// $previous_time is used as a key because it's identical when
// it needs to be, meaning points and ids are grouped.
array_push($ties[ $previous_time ]['points'], $result->points, $previous_points);
array_push($ties[ $previous_time ]['id'], $id, $previous_id);
// Remove duplicate values.
$ties[ $previous_time ]['points'] = array_unique($ties[ $previous_time ]['points']);
$ties[ $previous_time ]['id'] = array_unique($ties[ $previous_time ]['id']);
}
//Set these values for the next iteration to compare against
$previous_id = $id;
$previous_points = $result->points;
$previous_time = $result->lap_time;
}
return $ties;
}
protected function average_array_values($values)
{
$number_of_elements = count($values);
$total_points = array_sum($values);
return $total_points / $number_of_elements;
}