# 表及时分配

``````select timefield from entries where uid = ? order by timefield;
``````

0

## 7 答案

``````SELECT percentile_disc(0.95)
WITHIN GROUP (ORDER BY response_time)
FROM pageviews;
``````
0

@Michal

``````select timefield from entries
where uid = ? and id % 150 = 0 order by timefield;
``````

0

``````select @rownum:[email protected]+1 rownum, entries.*
from (select @rownum:=0) r, entries
where uid = ? and rownum % 150 = 0
``````

0

``````SELECT DATEADD(day, DATEDIFF(day, 0, timefield), 0) AS bucket -- choose an appropriate granularity (days used here)
,COUNT(*)
FROM entries
WHERE uid = ?
GROUP BY DATEADD(day, DATEDIFF(day, 0, timefield), 0)
ORDER BY DATEADD(day, DATEDIFF(day, 0, timefield), 0)
``````

``````SELECT uid
,bucket
,COUNT(*) AS measure
FROM (
SELECT uid
,DATEADD(day, DATEDIFF(day, 0, timefield), 0) AS bucket
FROM entries
) AS buckets
GROUP BY uid
,bucket
ORDER BY uid
,bucket
``````

0

Michal Sznajder几乎拥有它，但不能在SQL中的WHERE子句中使用列别名。所以你必须把它作为派生表来包装。我试过了，它返回20行：

``````SELECT * FROM (
SELECT @rownum:[email protected]+1 AS rownum, e.*
FROM (SELECT @rownum := 0) r, entries e) AS e2
WHERE uid = ? AND rownum % 150 = 0;
``````
0

``````select timefield
from entries
where rand() = .01 --will return 1% of rows adjust as needed.
``````

0

0