-1
我下表獲取最後價值
+-----------------------+-------+----------+---------+----------+
|date |curency|high_price|low_price|last_price|
+-----------------------+-------+----------+---------+----------+
|2014-01-16 16:01:42.000|2 |24.98 |23.9 |24.2 |
+-----------------------+-------+----------+---------+----------+
|2014-01-16 16:01:32.000|2 |24.98 |23.9 |24.12202 |
+-----------------------+-------+----------+---------+----------+
|2014-01-16 16:01:22.000|2 |24.98 |23.9 |24.12202 |
+-----------------------+-------+----------+---------+----------+
|2014-01-16 16:01:12.000|2 |24.98 |23.9 |24.21626 |
+-----------------------+-------+----------+---------+----------+
|2014-01-16 16:01:02.000|2 |24.98 |23.9 |24.11102 |
+-----------------------+-------+----------+---------+----------+
|2014-01-16 16:00:52.000|2 |24.98 |23.9 |24.21628 |
+-----------------------+-------+----------+---------+----------+
|2014-01-16 16:00:42.000|2 |24.98 |23.9 |24.2 |
+-----------------------+-------+----------+---------+----------+
|2014-01-16 16:00:32.000|2 |24.98 |23.9 |24.2 |
+-----------------------+-------+----------+---------+----------+
有我用下面的查詢組例如通過時間間隔15分鐘:
WITH x AS (
SELECT
last_price,
high_price,
low_price,
dateadd(MINUTE, datediff(MINUTE, 0,[date])/1*1,0) AS SERVERTIME
FROM
m_cPrice
WHERE
curency=2
GROUP BY
last_price,
high_price,
low_price,
datediff(MINUTE, 0,[date])/1*1
)
SELECT
last_price,
high_price,
low_price ,
dateadd(MINUTE, datediff(MINUTE, 0,SERVERTIME)/1*1,0) as STIME
FROM
x
WHERE
DATEPART(MINUTE,SERVERTIME)%15=0
ORDER BY
STIME DESC
問題是,它得到從該分鐘或間隔的所有值,我只需要不是所有的最後一個值
在此先感謝
添加(MAX [日期])與MAX – Mihai
does not工作已經檢查 –