T
T
Tonako2016-04-01 08:11:12
SQL
Tonako, 2016-04-01 08:11:12

SQL Counting Unique Values?

There is a table orders:
id|user_id
in this table all orders of all users
how to calculate how many unique users user_id in this table?
there is no separate users table, so it is not possible to calculate normally

Answer the question

In order to leave comments, you need to log in

2 answer(s)
D
Dmitry Eremin, 2016-04-01
@EreminD

The query above will return a list of unique values
​​This query will return the count
SELECT COUNT(DISTINCT user_id) FROM orders

D
Dmitry Kovalsky, 2016-04-01
@dmitryKovalskiy

Gentlemen, you must be joking.

SELECT userId,COUNT(userId)
FROM orders
GROUP BY userId

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question