Checksum of SELECT results in MySQL

余生颓废 提交于 2019-12-01 09:44:01

问题


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;

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.


回答1:


The problem is that CONCAT and SUM are not compatible in this format.

CONCAT is designed to run once per row in your result set on the arguments as defined by that row.

SUM is an aggregate function, designed to run on a full result set.

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.

You could try:

SELECT CONCAT(
    (SELECT sum(crc32(column_one)) FROM database.table),
    (SELECT sum(crc32(column_two)) FROM database.table)
);

or

SELECT sum(crc32(column_one)), sum(crc32(column_two))
FROM database.table;

and concatenate them with your client language.



来源:https://stackoverflow.com/questions/5955776/checksum-of-select-results-in-mysql

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!