Dim clst As new List(of String)
For Each c As Col In Tables("表A").Cols
If c.IsNumeric Then clst.Add(c.Name)
Next
If clst.Count > 0 Then
Dim s1 As String = "select '{0}' as 列名, sum({0}) as 合计 from {表A}"
Dim sql As String
For Each cn As String In clst
sql &= CExp(s1,cn) & " union all "
Next
sql = "select * from (" & sql.SubString(0,sql.Length - 10) & ") as a order by a.合计"
Output.Show(sql)
Dim cmd As new SQLCommand
cmd.CommandText = sql
Dim dt As DataTable = cmd.ExecuteReader
s1 =dt.DataRows(0)("列名")
For i As Integer = 1 To dt.DataRows.Count-1
If dt.DataRows(i-1)("合计") = dt.DataRows(i)("合计") Then
s1 &= "," & dt.DataRows(i)("列名")
Else
Output.Show(s1)
s1 =dt.DataRows(i)("列名")
End If
Next
Output.Show(s1)
End If