        (membero field fields-fields)))
 
 (defn- aggregate-fieldo [{{ag-type :aggregation-type, ag-field :field} :aggregation} field]
-  (all (membero ag-type [:count :avg :sum :stddev :distinct])
-       (== field (if (contains? #{:count :distinct} ag-type)
+  (all (== field (if (contains? #{:count :distinct} ag-type)
                    {:base-type    :IntegerField
                     :field-name   :count
                     :special-type :number}
                    (-> ag-field
                        (select-keys [:base-type :special-type])
                        (assoc :field-name (if (= ag-type :distinct) :count
-                                              ag-type)))))))
+                                              ag-type)))))
+       (membero ag-type [:count :avg :sum :stddev :distinct])))
 
 (defn- valid-nameo [{:keys [result-keys]} field]
   (fresh [field-name]

                                    (conj! fields f)))
                          query)
    (assoc query
           :result-keys  (vec (keys (first results)))
           :query-fields (mapv collapse-field (persistent! fields))
           :fields       (mapv collapse-field (:fields query))
           :breakout     (mapv collapse-field (:breakout query)))))

             (distincto q)
             (everyg (partial fieldo query) q)
             (everyg (fn [i]
                       (fields< query (cols i) (cols (inc i))))
                     (range 0 (dec num-cols)))))))


