MySQL中SELECT结果的校验和 [英] Checksum of SELECT results in MySQL
问题描述
尝试获取SELECT语句的结果的校验和,请尝试此操作
Trying to get a check sum of results of a SELECT statement, tried this
SELECT sum(crc32(column_one))
FROM database.table;
哪个可行,但这不可行:
Which worked, but this did not work:
SELECT CONCAT(sum(crc32(column_one)),sum(crc32(column_two)))
FROM database.table;
开放供参考,主要思想是从SELECT语句中获取行和列结果的SUM的有效校验和.
Open to suggestions, main idea is to get a valid checksum for the SUM of the results of rows and columns from a SELECT statement.
推荐答案
问题是CONCAT
和SUM
与此格式不兼容.
The problem is that CONCAT
and SUM
are not compatible in this format.
CONCAT
设计为在结果集中的每一行中针对该行定义的参数运行一次.
CONCAT
is designed to run once per row in your result set on the arguments as defined by that row.
SUM
是一个聚合函数,旨在在完整结果集上运行.
SUM
is an aggregate function, designed to run on a full result set.
CRC32
与CONCAT
具有相同的功能类别.
CRC32
is of the same class of functions as CONCAT
.
因此,您嵌套的函数无法很好地配合使用.
So, you've got functions nested in a way that just don't play nicely together.
您可以尝试:
SELECT CONCAT(
(SELECT sum(crc32(column_one)) FROM database.table),
(SELECT sum(crc32(column_two)) FROM database.table)
);
或
SELECT sum(crc32(column_one)), sum(crc32(column_two))
FROM database.table;
并将它们与您的客户语言连接起来.
and concatenate them with your client language.
这篇关于MySQL中SELECT结果的校验和的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!