首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用SQL处理多稀疏矩阵

使用SQL处理多稀疏矩阵
EN

Stack Overflow用户
提问于 2012-03-28 23:30:34
回答 1查看 352关注 0票数 1

我有一个这样的模型:

代码语言:javascript
复制
matrices (
    matricesID integer;
    x integer;
    y integer;
    value float;
)

所以表中将存储许多矩阵数据,现在我需要逐边获取每个矩阵的平均值,即,如果一个矩阵是20 * 30,并且具有(5,3),(5,7),(5,15),(12,4),(17,5),(17,10)中的值,我需要获取四组数据,一组用于所有的x=5值,一组用于所有的x=17值,一组用于所有的y=4值,另一组用于y=15的所有值,因为它们是x和y的最大/最小值。

有没有办法用easy SQL来实现这一点呢?

任何想法都将受到感谢。

BR

爱德华一世

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2012-03-28 23:56:07

这只是一个猜测,因为我在问题领域没有太多的经验:

代码语言:javascript
复制
select matricesID
    , (select avg(value) from matrices where matricesID = a.matricesID and x = a.minx) as avgofminx
    , (select avg(value) from matrices where matricesID = a.matricesID and x = a.maxx) as avgofmaxx
    , (select avg(value) from matrices where matricesID = a.matricesID and y = a.miny) as avgofminy
    , (select avg(value) from matrices where matricesID = a.matricesID and y = a.maxy) as avgofmaxy
from (
    select matricesID
        , min(x) as minx
        , max(x) as maxx
        , min(y) as miny
        , max(y) as maxy
    from matrices
    group by matricesID
) as a

这是在SQL Server中运行的,但语法非常简单,希望它能在您所使用的任何DBMS中运行

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/9910851

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档