title: **SQLAlchemy**:Get a count of one column where another column is distinct
body: <p>This is killing me! I'm sure it's a gap in my SQL knowledge, but I'm having massive trouble solving this issue.
  I need to get a count of all orders for each country. The catch is the orders need to have a unique user_id in order to include only unique customers in the count.
  Here's what I have presently, it returns a total count including orders from the same user_id.</p>
  
  <pre><code>country_col = model.Order.__table__.c.shipping_country_code
  country_q = model.Session.query(country_col,
                                      func.count('*'))\
          join(model.Order.cart).\
          join(model.Cart.items).\
          join(model.CartItem.product).\
          filter(model.Product.project_id == project.id).\
          group_by(country_col).\
          order_by(func.count('*').desc())
  
  country_q.all()
  </code></pre>
  
  <p>I'm sorry if this seems to be a duplicate. I've read all of the StackOverflow questions and their comments/answers, but I can't translate the solutions to my problem, unfortunately.</p>