表格内容:
number value 1 123 1 345
我有上面的表格内容,当我选择时,我想要低于输出:
number value 1 123,345
但是我得到了
number value 1 345
sql am using:
Option Explicit
Sub DeDupeRange()
Dim rngSelection As Range
Set rngSelection = Application.Selection
Dim rngDeDuped As Range
Dim rngLoop As Range
For Each rngLoop In rngSelection
If rngDeDuped Is Nothing Then
Set rngDeDuped = rngLoop
Else
If Intersect(rngLoop, rngDeDuped) Is Nothing Then
Set rngDeDuped = Union(rngDeDuped, rngLoop)
End If
End If
Next
Debug.Print rngSelection.Address 'result is A1:A2,A2
Debug.Print rngDeDuped.Address 'result is A1:A2
End Sub
使用value where子句的原因是
SELECT number, GROUP_CONCAT(value SEPARATOR ', ') as val,
from table_name
where value="345"
group by number
1与number
相关联)。所以我希望两个值都用逗号分隔。value
的where子句,因为我也想通过它查询value
值)任何人都可以告诉我哪里出错了吗?
答案 0 :(得分:0)
我不认为您在问题中提到的查询是您实际运行的内容,或者生成您向我们展示的输出的内容。相反,我认为你运行了这个查询:
SELECT
number,
GROUP_CONCAT(value SEPARATOR ', ') AS val
FROM table_name
WHERE value = '345'
GROUP BY number
问题是你的WHERE
子句,它将聚合重新排列到一条记录。删除它,你应该得到你期望的结果:
SELECT
number,
GROUP_CONCAT(value) AS val
FROM table_name
GROUP BY number
答案 1 :(得分:0)
我想你想要:
SELECT number, GROUP_CONCAT(value SEPARATOR ', ') as val
FROM table_name
GROUP BY number
HAVING MAX(value = '345') > 0;
这将返回任何具有'345'
至少一个值的数字的所有值。
Here是一个SQL小提琴,表明它有效。