Mysql 多行解析逻辑
Mysql Parsing logic on Multiple rows
我使用以下引用解析查询
link1 -
link2
输入将在下面的 Col1 中显示,在上述参考中的@input link 我只考虑 1 条记录并为每个单元格应用解析逻辑,但问题在于 多个行(n 行) 并将结果与解析逻辑组合。
Col1
--------------
22:4,33:4
33:6,89:7,69:2,63:2
78:6
blank record
22:6,63:1
我想创建单个查询,与我要求的参考link相同。
Expected Output
xyz count
------------
22 10
33 10
89 7
69 2
63 3
78 6
我试过解决方案 Passing values with this conditions
- where 条件在(我的查询)
中通过 1 by 1 col1
- MAX (col1)
- group_concat
但我没有得到预期的输出来满足单个查询中的所有内容。
我终于找到了我的问题的解决方案。 group_concat 为此工作
@input= (select group_concat(Col1) from (select Col1 from table limit 10)s);
group_concat 会将 Col1 的所有行合并为逗号分隔的字符串
22:4,33:4,33:6,89:7,69:2,63:2,78:6,blank record,22:6,63:1
因为我们现在只有一个字符串,所以我们可以应用与 link 1 中所示相同的逻辑
我们可以用REPLACE命令替换空白记录并忽略它。
使用来自 link1 个结果的逻辑后的输出
xyz count
------------
22 4
33 4
33 6
89 7
69 2
63 2
78 6
22 6
63 1
只需使用
分组
select xyz,sum(count) from (select link1 output)s group by xyz;
将为您提供最终输出
xyz count
------------
22 10
33 10
89 7
69 2
63 3
78 6
我使用以下引用解析查询
link1 -
输入将在下面的 Col1 中显示,在上述参考中的@input link 我只考虑 1 条记录并为每个单元格应用解析逻辑,但问题在于 多个行(n 行) 并将结果与解析逻辑组合。
Col1
--------------
22:4,33:4
33:6,89:7,69:2,63:2
78:6
blank record
22:6,63:1
我想创建单个查询,与我要求的参考link相同。
Expected Output
xyz count
------------
22 10
33 10
89 7
69 2
63 3
78 6
我试过解决方案 Passing values with this conditions
- where 条件在(我的查询) 中通过 1 by 1 col1
- MAX (col1)
- group_concat
但我没有得到预期的输出来满足单个查询中的所有内容。
我终于找到了我的问题的解决方案。 group_concat 为此工作
@input= (select group_concat(Col1) from (select Col1 from table limit 10)s);
group_concat 会将 Col1 的所有行合并为逗号分隔的字符串
22:4,33:4,33:6,89:7,69:2,63:2,78:6,blank record,22:6,63:1
因为我们现在只有一个字符串,所以我们可以应用与 link 1 中所示相同的逻辑 我们可以用REPLACE命令替换空白记录并忽略它。
使用来自 link1 个结果的逻辑后的输出
xyz count
------------
22 4
33 4
33 6
89 7
69 2
63 2
78 6
22 6
63 1
只需使用
分组select xyz,sum(count) from (select link1 output)s group by xyz;
将为您提供最终输出
xyz count
------------
22 10
33 10
89 7
69 2
63 3
78 6