当前位置: 代码迷 >> Sql Server >> 从表里根据时间随机抽取一个字段生成试图,该怎么解决
  详细解决方案

从表里根据时间随机抽取一个字段生成试图,该怎么解决

热度:33   发布时间:2016-04-27 18:01:51.0
从表里根据时间随机抽取一个字段生成试图
表结构:
每六秒一个值 数据量太大 要做一个折线图 想每小时抽取一个值 生成视图 


------解决方案--------------------
SQL code
select  distinct b.*from  tb across apply  (select top 1 * from tb where convert(varchar(13),riqi,120)=convert(varchar(13),t.riqi,120) order by riqi)b
------解决方案--------------------
SQL code
SELECT b.*FROM (SELECT DISTINCT CAST(CONVERT(VARCHAR(14),rigi,121)+'00' AS DATETIME) AS rigi FROM TABLE1 )AS aCROSS APPLY(SELECT TOP 1 * FROM table1 WHERE DATEDIFF(h,a.rigi,rigi)=0 ORDER BY NEWID()) AS b
  相关解决方案