1
From https://github.com/tonsky/datascript爲什麼這個數據庫查詢是聚合的?
(->
(d/q '[:find ?color (max ?amount ?x) (min ?amount ?x)
:in [[?color ?x]] ?amount]
[[:red 10] [:red 20] [:red 30] [:red 40] [:red 50]
[:blue 7] [:blue 8]]
4)
pr-str
js/console.log)
;;; ([:red [20 30 40 50] [10 20 30 40]] [:blue [7 8] [7 8]])
(->
(d/q '[:find ?color (max ?amount ?x) (min ?amount ?x)
:in [[?color ?x]] ?amount]
[[:red 10] [:red 20] [:red 30] [:red 40] [:red 50]
[:blue 7] [:blue 8]]
3)
pr-str
js/console.log)
;;; ([:red [30 40 50] [10 20 30]] [:blue [7 8] [7 8]])
(->
(d/q '[:find ?color (max ?amount ?x) (min ?amount ?x)
:in [[?color ?x]] ?amount]
[[:red 10] [:red 20] [:red 30] [:red 40] [:red 50]
[:blue 7] [:blue 8]]
2)
pr-str
js/console.log)
;;; ([:red [40 50] [10 20]] [:blue [7 8] [7 8]])
所以,這不是一個關於它是做什麼的問題,這是它是如何(或者至少是爲什麼)做的問題。 max和min分別是返回其後續整數的最大值或最小值的函數。 ?amount
如何計算限制聚合計數?爲什麼這些東西聚合呢?代碼如何運行以便聚合。我真的沒有看到這個代碼是如何產生它所做的結果的。
澄清:(max N coll)是coll的前N個值。同樣的分鐘,這是N最低的科爾。 –