我有一个非常大的SQL数据库,我将数据提取到网页。我想取每12个值,而不是拉每个值。有没有办法修改我当前的select语句?
SELECT *
FROM (
SELECT CAST(DateTimeUTC as SmallDateTime) as [DateTime],
CASE When DataValue = '-9999' Then null
When DataValue < '-60' Then null
Else DataValue
End DataValue, VariableID
FROM DataValues
WHERE SiteID = @siteID and VariableID IN(9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30)
) TableDate
PIVOT (SUM(DataValue) FOR VariableID IN ([9],[10],[11],[12],[13],[14],[15],[16],[17],[18],[19],[20],[21],[22],[23],[24],[25],[26],[27],[28],[29],[30])) PivotTable ORDER BY [DateTime]
END
除了数据从一列到下一列错开之外,这是有效的。我不确定为什么所有的数据点都不会从同一个位置开始。
请参阅下面的屏幕截图。
答案 0 :(得分:1)
使用此理论(SQL Server) -
class Sticker(models.Model):
name = models.CharField(max_length=255,)
slug = models.CharField(max_length=255,)
image = models.ImageField(upload_to='stickers')
#requirements = ?
像这样 -
if books_read >= 50:
return True
答案 1 :(得分:1)
,或者
Select * from DataValues d
where (Select count(*) from datavalues
where DateTimeUTC < d.DateTimeUTC) % 12 = 0
从第12行开始,而不是第一行,
Select * from DataValues d
where (Select count(*) from datavalues
where DateTimeUTC <= d.DateTimeUTC) % 12 = 0
或
Select * from DataValues d
where (Select count(*) from datavalues
where DateTimeUTC < d.DateTimeUTC) % 12 = 11