mysql - sql怎样删除所有值总和小于某个阈值的行?
PHP中文网
PHP中文网 2017-04-17 14:25:19
0
2
644

如果一张表只有3个字段A,B,C
那么
delete from table where (A+B+C) < t; 即可

但是一张表有几千个字段(可能有些夸张,但是注意就是几千个,请针对这张表,不要提分表的方案)
怎么解决?

PHP中文网
PHP中文网

认证0级讲师

reply all(2)
迷茫

You can do this by using a cursor in the stored procedure. For example, if you have 100 fields and want the sum of 99 columns to be less than 1000, you can exclude one of the columns (dep_name). You only need to manually exclude this column in SQL. Yes, if there are few columns that need to be calculated, you can just enumerate and add them as you said.

Peter_Zhu

As long as your a b c are all numerical fields, your SQL statement will be enough

I didn’t see the question clearly, I’m off topic,
Please add some more

Use

select COLUMN_NAME from information_schema.COLUMNS where table_name = 'table_name'

Get all the field names, and then use the obtained field names to assemble the delete sql you want,

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template