# USQL for getting numbers of users by country

**URL:** <https://community.dynatrace.com/t/usql-for-getting-numbers-of-users-by-country/45954>\
**Category:** Real User Monitoring\
**Tags:** real-user-monitoring-classic, usql, user-sessions\
**Created:** [June 6, 2024, 2:36pm UTC](https://community.dynatrace.com/t/usql-for-getting-numbers-of-users-by-country/45954 "2024-06-06T14:36:04Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![soportetr](https://avatars.discourse-cdn.com/v4/letter/s/c6cbf5/32.png) [@soportetr](https://community.dynatrace.com/u/soportetr)\
**Post date:** [June 6, 2024, 2:36pm UTC](https://community.dynatrace.com/t/usql-for-getting-numbers-of-users-by-country/45954/1 "2024-06-06T14:36:04Z")

</div>

Hi everyone,

I have been trying a query to get the amount of users connected per month and also get the users connected per country but the numbers do not match.

What would be the most optimal USQL for those queries?

Thanks in advance

---

<div class="post-metadata">

**Author:** ![Gosia\_Murawska](https://avatars.discourse-cdn.com/v4/letter/g/2bfe46/32.png) [@Gosia\_Murawska](https://community.dynatrace.com/u/Gosia_Murawska)\
**Post date:** [August 7, 2024, 11:56am UTC](https://community.dynatrace.com/t/usql-for-getting-numbers-of-users-by-country/45954/2 "2024-08-07T11:56:55Z")

</div>

Hi&nbsp;[@soportetr](https://community.dynatrace.com/user/41008),

Let me quote the answer of one of our specialists:

**userId** &nbsp;- for tagged users  
**internalUserId** &nbsp;- for anonymous users  
**COUNT** &nbsp;- general amount of values  
**COUNT(DISTINCT)**&nbsp;- amount of unique values. And its result can be approzimate and fuzzy. It is in our USQL documentation&nbsp;[link](https://docs.dynatrace.com/docs/platform-modules/digital-experience/session-segmentation/custom-queries-segmentation-and-aggregation-of-session-data#:~:text=Example-,Results%20returned,-by%20the%20COUNT).

If extrapolation took place - the results will be very approximate and will be big chance that they will not match.

1. Per country:  
`SELECT country, COUNT(DISTINCT userId) FROM usersession GROUP BY country`

2. Per month:  
`SELECT MONTH(startTime), COUNT(DISTINCT userId) FROM usersession GROUP BY MONTH(startTime)`

Let us know if it helps!
