如何使用标量值函数结果对整个SQL查询进行分组。
SELECT Col1,Col2,udf_IsNumaric_Get(Param1,Param2)
FROM Table1
WHERE Col1 LIKE '%123%'
GROUP BY --Function result
ORDER BY --Function result
OR
SELECT Col1,Col2,(SELECT COUNT(*) FROM Table2) AS Count
FROM Table1
WHERE Col1 LIKE '%123%'
GROUP BY --Count
ORDER BY --Count
是否可以使用udf_IsNumaric_Get
标量值函数的输出或使用第二个示例中的SELECT
语句对整个SQL查询进行分组。
答案 0 :(得分:2)
您可以使用子查询来实现它:
SELECT t.Col1,t.Col2,t.Count FROM
(SELECT Col1,Col2,(SELECT COUNT(*) FROM Table2) AS Count
FROM Table1
WHERE Col1 LIKE '%123%') as t
GROUP BY Count
ORDER BY Count