2
我有一個50k行數據集並且想要在有序集合中選擇每10個百分點值。理想情況下,它會返回11個值,與非NULL值相等。在MYSQL中從數據集中選擇每個X百分點值
我試圖避免選擇整個列,並在PHP中做,或做10個查詢,每個選擇基於總數的單個行。
這將在每個用戶對不同列的請求中完成7次。 (其它查詢參數會發生變化,所以我不能緩存它。)
更新:我試圖避免這種情況:
$query = "SELECT BLAH BLAH" ;
$result = mysql_query($query);
$num_of_results = mysql_num_rows($result);
//divide count by 10 to get percentile sizes
$number_of_percentiles= 10;
$percentile_size = $num_of_results/ $number_of_percentiles;
//take each of the percentiles of the sample set
for ($a=0; $a<= $number_of_percentiles; $a++){
$query = "SELECT BLAH BLAH
LIMIT ". ($a * $percentile_size).",1";
$result = mysql_query($query);
$percentile_array[] = mysql_fetch_assoc($result);
}
MySQL不具備您通常用於此類需求的分析/排名/窗口功能。 – 2010-11-23 06:02:59
做你的需要在哪裏過濾你的`選擇等等等等? – ajreal 2010-12-02 20:16:53