我已经尝试了一段时间,提出了一个代码,计算条纹从几个列在同一时间,对于一个表,我需要找到值的条纹高于0。首先,我设法使用了一个显示rungroup的公式,该列表示在其各自的行中与所讨论的数据不同的数据数。如下所示:
select descrip,
`1.01`,
(select count(*)
from `all_data` dp
where dp.`1.01` <> dpo.`1.01`
and dp.descrip <= dpo.descrip) as rungroup,
`1.02`,
(select count(*)
from `all_data` dp
where dp.`1.02` <> dpo.`1.02`
and dp.descrip <= dpo.descrip) as rungroup_2
from `all_data` dpo;
1.01和1.02是列的名称,使用description对数据进行排序。这个模型工作到目前为止,但我不知道我如何在另一个查询中使用它来显示两列的条纹。有这样的方法吗?
您应该使用您的2列创建UNION
查询。
像这样
SELECT descrip, thecol,
(select count(*)
from `all_data` dp
where (dp.`1.01` <> dpo.thecol AND dp.`1.02` <> dpo.thecol)
and dp.descrip <= dpo.descrip) as rungroup
FROM
(
SELECT *
FROM
(
SELECT '1.01' AS origcol, descrip, `1.01` AS thecol from `all_data`
UNION ALL
SELECT '1.02' AS origcol, descrip, `1.02` AS thecol from `all_data`
)
ORDER BY descrip, thecol
) dpo;
然而,我对这部分完全不确定:
where (dp.`1.01` <> dpo.thecol AND dp.`1.02` <> dpo.thecol)
可能是OR
而不是AND
。没有看到数据是不容易的。
只是玩弄我的查询,分解只得到UNION子查询,修复…你会得到它的