2
我正在使用具有500,000條記錄的MySql表。該表包含一個字段(abbrevName),用於存儲另一個字段名稱前兩個字母的兩個字符表示。MySQL查詢爲基於迭代方式的字段賦值
例如AA AB AC等。
我想要實現的是根據記錄abbrevName的值設置另一個字段(pgNo)的值,該字段存儲頁碼的值。
因此,一個縮寫名爲'AA'的記錄可能會得到1的頁碼,'AB'可能會得到2的頁碼,依此類推。
問題在於雖然多個記錄可能具有相同的頁碼(畢竟多個實體可能有一個名字以'AA'開頭),但是一旦具有相同頁碼的記錄數量達到250,頁碼必須增加一個。因此,在頁碼爲1的250'AA'記錄之後,我們必須爲頁碼2分配更多'AA記錄,等等。
我的僞代碼看起來是這樣的:
-Count distinct abbrevNames
-Count distinct abbrevNames with more than 250 records
-For the above abbrevNames count the the sum of each divided by 250
-Output a temporary table sorted by abbrevName
-Use the total number of distinct page numbers with 250 or less records to assign page numbers incrementally
我真的很掙扎在接近這一點,任何人都可以用我的邏輯或一些代碼幫助查詢把任何東西在一起嗎?
等一下,發現一個錯誤,糾正它。 – fancyPants
我應該補充說,pagenumber值全部爲空 –
更正(我希望),請再試一次。 – fancyPants