如何使用SQL基于两列的平均值来划分表 [英] How to divide a table using SQL based on average of two columns

查看:158
本文介绍了如何使用SQL基于两列的平均值来划分表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,



在我的桌子上我有三列



Column1 - 名称 - 拥有独特的数据

Column2 - PD1 - 有数值

Column3 - PD2 - 有数值



我的要求我必须根据PD1的平均值和PD2的平均值将我的表分成三个不同的表。



(即)三个表中PD1的平均值应该是几乎相等。因此PD2的平均值也应该几乎相等。



例如



我的表有这样的数据



Hi All,

In my table I have three columns

Column1 - Name - Having unique data
Column2 - PD1 - Having numeric values
Column3 - PD2 - Having numeric values

My requirement is I have to divide my table into three different tables based on Average values of PD1 and Average values of PD2.

(ie) In three tables Average of PD1 should be nearly equal. Consequently Average of PD2 should also be nearly equal.

For Example

My table having data like this

Name 	PD1	PD2
A	50	400
B	60	200
C	40	400
D	30	300
E	70	500
F	20	700
G	10	200
H	20	400
I	40	200
J	60	300
K	50	300
L	50	200
M	60	100





三个表中PD1的平均值几乎等于43和PD2的平均值几乎等于323.

每个表中的行数可能会有所不同。



如何使用SQL



In three tables Average of PD1 nearly equals to 43 and Average of PD2 nearly equals to 323.
Count of rows in each tables may vary.

How to divide the table using SQL

推荐答案

近乎一词意味着模糊。你自己具体而精确地定义它会有问题,更不用说机器了。事实上,您的问题属于优化问题,可能存在许多解决方案。 SQL和普通编程都无法解决它。
The term "nearly" implies fuzziness. You would have problem defining it concretely and precisely yourself, let alone the machine. In fact, your problem belongs to that of optimization which has potentially many solutions. Neither SQL nor ordinary programming can solve it.


这篇关于如何使用SQL基于两列的平均值来划分表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆