n****n 发帖数: 59 | 1 rt。俺是sql新手,google了半天也没发现什么好方法。版上的牛牛们有什么办法吗?
谢谢 |
i****a 发帖数: 36252 | 2 what is "moving" avg?
【在 n****n 的大作中提到】 : rt。俺是sql新手,google了半天也没发现什么好方法。版上的牛牛们有什么办法吗? : 谢谢
|
B*****g 发帖数: 34098 | 3 用不着触动妞妞吧
http://oreilly.com/catalog/transqlcook/chapter/ch08.html
【在 n****n 的大作中提到】 : rt。俺是sql新手,google了半天也没发现什么好方法。版上的牛牛们有什么办法吗? : 谢谢
|
g***l 发帖数: 18555 | 4 TSQL不是做统计用的,SQL SERVER 有这些
SELECT VAR(grandtotal_amount ) 'Variance',
STDEVP(grandtotal_amount ) 'Standard Deviation',
STDEV(grandtotal_amount ) 'Standard Deviation',
VARP(grandtotal_amount) 'Variance for the Population'
FROM ordr |
y****w 发帖数: 3747 | 5 google "sql olap function window rows range".
【在 n****n 的大作中提到】 : rt。俺是sql新手,google了半天也没发现什么好方法。版上的牛牛们有什么办法吗? : 谢谢
|
B*****g 发帖数: 34098 | 6 TSQL
【在 y****w 的大作中提到】 : google "sql olap function window rows range".
|
y****w 发帖数: 3747 | 7 这依然是咱们说的数据库版sql问题90%可以partition by解决的范围。 移动么,
partition window前后范围都是可以指定的,lag, first_value之类的都是特殊情况而
以。
【在 B*****g 的大作中提到】 : 用不着触动妞妞吧 : http://oreilly.com/catalog/transqlcook/chapter/ch08.html
|
y****w 发帖数: 3747 | 8 打回去再看。ctr+f "rows","range",“preceding”“following”
【在 B*****g 的大作中提到】 : TSQL
|
y****w 发帖数: 3747 | 9 select date, prod_name, store_name, dollars,
sum(dollars) over(partition by prod_name, store_name
order by extract(day from date)
---------------------------------------------------------
range between 3 preceding and 3 following) as olap_sum
----------------------------------------------------------
from sales natural join store
natural join period
natural join product
where month = 'MAR' and year = 2000 and prod_name = 'Earl Grey'
group by date, prod_name, store_name, dollars
order by store_name;
DATE PROD_NAME STORE_NAME DOLLARS OLAP_SUM
2000-03-04 Earl Grey Beaches Brew 24.50 90.50
2000-03-05 Earl Grey Beaches Brew 24.00 153.50
2000-03-05 Earl Grey Beaches Brew 42.00 153.50
2000-03-08 Earl Grey Beaches Brew 63.00 129.00
【在 B*****g 的大作中提到】 : TSQL
|
B*****g 发帖数: 34098 | 10 这个还真有,哈哈
【在 y****w 的大作中提到】 : 打回去再看。ctr+f "rows","range",“preceding”“following”
|
|
|
y****w 发帖数: 3747 | 11 你在oracle下做个测试看支持不。
【在 B*****g 的大作中提到】 : 这个还真有,哈哈
|
B*****g 发帖数: 34098 | 12 支持
【在 y****w 的大作中提到】 : 你在oracle下做个测试看支持不。
|
n****n 发帖数: 59 | 13 真是魔鬼定律啊,发帖后再google一下找到了好多。还是没法用云兄说的partition
window (俺用的是SQL Sever 2008,真的有这个功能吗?)。现在是这样做的
SELECT t1.ID, t1.Date, AVG(t1.Value), STDEV(t2.Value)
FROM table as t1
JOIN table as t2
ON t1.ID = t2.ID
AND t1.Date BETWEEN DATEADD(dd, -10, t2.Date) AND DATEADD(dd, -1, t2.Date)
GROUP BY t1.ID, t1.Date
ORDER BY t1.ID, t1.Date
另外看到有人说居然这里用cursor比set based方法好, http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=93911
不知真假,回头我再试试。 |
n****n 发帖数: 59 | 14 初衷其实是用sigma clip找outlier。因为所有数据都在sql sever里,大概有
500million rows。这种情况用统计软件会还是数据库好呢?
【在 g***l 的大作中提到】 : TSQL不是做统计用的,SQL SERVER 有这些 : SELECT VAR(grandtotal_amount ) 'Variance', : STDEVP(grandtotal_amount ) 'Standard Deviation', : STDEV(grandtotal_amount ) 'Standard Deviation', : VARP(grandtotal_amount) 'Variance for the Population' : FROM ordr
|
B*****g 发帖数: 34098 | 15 heihei, SQL Server 2012
【在 n****n 的大作中提到】 : 真是魔鬼定律啊,发帖后再google一下找到了好多。还是没法用云兄说的partition : window (俺用的是SQL Sever 2008,真的有这个功能吗?)。现在是这样做的 : SELECT t1.ID, t1.Date, AVG(t1.Value), STDEV(t2.Value) : FROM table as t1 : JOIN table as t2 : ON t1.ID = t2.ID : AND t1.Date BETWEEN DATEADD(dd, -10, t2.Date) AND DATEADD(dd, -1, t2.Date) : GROUP BY t1.ID, t1.Date : ORDER BY t1.ID, t1.Date : 另外看到有人说居然这里用cursor比set based方法好, http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=93911
|
n****n 发帖数: 59 | 16 酷啊!哪里可以看到2012的reference?msdn?
【在 B*****g 的大作中提到】 : heihei, SQL Server 2012
|