[英]Count maximum length of value in SQL Server
這是我的salesDetail
表及其[Kind of business]
列的小樣本:
kind of business
-------------------------------------
Retail and food services sales, total ………………………………………...…………………………………………………………………………………………………
Total (excl. motor vehicle and parts dealers) ………………………………………...…………………………………………………………………………………………………
我想用空格分隔所有數據,然后計算分隔字符串的最大長度。 我試過這段代碼
SELECT MAX(LEN(value))
FROM salesDetail
CROSS APPLY STRING_SPLIT([kind of business], ' ')
GROUP BY value
這將返回單個字符串的長度,而不是所有字符串的最大值。
結果顯示在下面的屏幕截圖中。
所以我嘗試了這段代碼:
SELECT MAX(COUNT(value))
FROM salesDetail
CROSS APPLY STRING_SPLIT([kind of business], ' ')
GROUP BY value
這會引發錯誤:
無法對包含聚合或子查詢的表達式執行聚合函數。
預期輸出:
147 (this is maximum number in this column)
我想要結果中的最大值,如圖所示
我應該如何解決這個問題?
只需刪除最后的GROUP BY
select max(len(value)) max_len
from salesDetail
CROSS APPLY STRING_SPLIT([kind of business], ' ')
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.