我有一个查询
select
sourceIP, SUM(sourceBytes)
from
flows
where
sourceBytes > 1000000
group by
sourceIP
此查询将带来在特定时间范围内在所有流中发送超过100万字节的IP地址,您必须输入
结果类似于
------------------------------------
| sourceIP | SUM_sourceBytes |
------------------------------------
| 64.124.201.151 | 4282590.0 |
| 10.105.2.10 | 4902509.0 |
| 10.103.70.243 | 2802715.0 |
| 10.103.77.143 | 3313370.0 |
| 10.105.32.29 | 2467183.0 |
| 10.105.96.148 | 8325356.0 |
| 10.103.73.206 | 1629768.0 |
------------------------------------
我希望源字节显示为MB格式。我需要嵌套查询吗?感谢。
答案 0 :(得分:7)
使用此表达式。 CONCAT是SQL Server 2012+并处理数据类型
...CONCAT(SUM(sourceBytes) / 1048576.0, 'MB')..
示例:
SELECT
sourceIP, CONCAT(SUM(sourceBytes) / 1048576.0, 'MB')
FROM
(VALUES ('10.105.2.10', 4902509.0), ('10.103.70.243', 2802715.0))
AS flows (sourceIP, sourceBytes)
WHERE
sourceBytes > 1000000
GROUP BY
sourceIP;
否则,您想要的预期输出是什么>