SQL-存储过程的结果

时间:2019-02-13 08:46:29

标签: mysql sql mariadb

我有两个表,A和B,我有第三个表,连接A和B,我使用mariadb数据库,我想将结果存储在第三个表result_A_B中,但是当我运行“ CALL”时出现此消息session_cpu_procedure()“:错误1136(21S01):列计数与第1行的值计数不匹配

CREATE TABLE result_A_B (
ID INT UNSIGNED NOT NULL AUTO_INCREMENT,
cid nvarchar(100) NOT NULL, 
time datetime NOT NULL,
OS nvarchar(100) NOT NULL, 
program nvarchar(100) NOT NULL,
nb_OS_by_program FLOAT NOT NULL,
cpu FLOAT,
last_line int NOT NULL,
PRIMARY KEY (`ID`),
UNIQUE KEY (`cid`,`time`,`program`) ) ENGINE=InnoDB;


DELIMITER |
CREATE PROCEDURE session_cpu_procedure()
BEGIN
TRUNCATE result_session_cpu_CPLSVFX201P;
INSERT INTO result_session_cpu_CPLSVFX201P
SELECT DISTINCT C.cid,  C.time, C.OS, C.program, COUNT(*) as nb_OS_by_program, O.cpu, C.last_line 
FROM session_test C LEFT outer JOIN cpu_test O ON O.sid2 = C.cid and O.time = C.time and C.PROGRAM=O.MODULE 
where C.time
GROUP BY C.time, C.OS, C.program, C.last_line;
END |
DELIMITER ;

CALL session_cpu_procedure();

我想知道如何解决此错误:错误1136(21S01):列数与第1行的值计数不匹配

1 个答案:

答案 0 :(得分:2)

您有一个包含8列的表格。

您的// Gamma0 var gamma0xh = w[(i-15) * 2]; var gamma0xl = w[(i-15) * 2 + 1]; var gamma0h = ((gamma0xl << 31) | (gamma0xh >>> 1)) ^ ((gamma0xl << 24) | (gamma0xh >>> 8)) ^ (gamma0xh >>> 7); var gamma0l = ((gamma0xh << 31) | (gamma0xl >>> 1)) ^ ((gamma0xh << 24) | (gamma0xl >>> 8)) ^ ((gamma0xh << 25) | (gamma0xl >>> 7)); // Gamma1 var gamma1xh = w[(i-2) * 2]; var gamma1xl = w[(i-2) * 2 + 1]; var gamma1h = ((gamma1xl << 13) | (gamma1xh >>> 19)) ^ ((gamma1xh << 3) | (gamma1xl >>> 29)) ^ (gamma1xh >>> 6); var gamma1l = ((gamma1xh << 13) | (gamma1xl >>> 19)) ^ ((gamma1xl << 3) | (gamma1xh >>> 29)) ^ ((gamma1xh << 26) | (gamma1xl >>> 6)); 语句有7列。

这产生了很容易解释的错误。

选项1:

由于已经有了UNIQUE键,因此将其作为主键并删除AUTO_INCREMENT列。

选项2:

在您的SELECT... INSERT中,要明确列出省略auto_increment列的列:

INSERT SELECT