How to avoid error “aggregate functions are not allowed in WHERE”

后端 未结 3 1637
刺人心
刺人心 2020-12-13 23:19

This sql code throws an

aggregate functions are not allowed in WHERE

SELECT o.ID ,  count(p.CAT)
FROM Orders o
INNER JO         


        
3条回答
  •  野趣味
    野趣味 (楼主)
    2020-12-13 23:50

    Will self join will go for a toss with join where we have a condition to list prices that are greater than the median of the prices listed in the order table?

    Eg. order_item, Order_Price

    Since aggregate functions cannot be used in a WHERE clause >

    select a.order_item_product_price, count(distinct 
    a.order_item_product_price) from 
    default.order_items a , default.order_items b
    where a.order_item_product_price = b.order_item_product_price
    group by a.order_item_product_price
    having a.order_item_product_price > appx_median(b.order_item_product_price)
    order by a.order_item_product_price limit 10
    

提交回复
热议问题