在SQL中获取nvarchar的AVG [英] Get an AVG of a nvarchar in SQL

查看:92
本文介绍了在SQL中获取nvarchar的AVG的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我想获取nvarchar的平均值.

这是一个示例:

Hi,

I want to get the average of nvarchar.

Here is an example:

Date           Dir<br />
2011/04/19     ESE<br />
2011/04/19     WNE<br />
2011/04/19     ESE





Is possible to get the average of the column Dir in a SQL Proc?

推荐答案

需要将列数据分为两列,然后通过转换使用平均值函数日期浮动.

以下是示例:
You need to break the column data into two columns and then use the average function by converting the date into float.

Following is the example:
DECLARE @test_date TABLE (dt datetime)

INSERT INTO @test_date VALUES (GETDATE() + 1)
INSERT INTO @test_date VALUES (GETDATE() + 2)
INSERT INTO @test_date VALUES (GETDATE() + 3)

SELECT CONVERT(char(8),CAST(AVG(CAST(dt AS FLOAT) - FLOOR(CAST(dt AS FLOAT))) AS datetime),108) FROM @test_date


这篇关于在SQL中获取nvarchar的AVG的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆