I am trying to create a query that will return results for the number of distinct users who have accessed something by date. Right now I have a query that will display 2 columns, the first being date and the second being user name. It will list all the distinct users who accessed the application on a certain date but they will each have their own distinct row. Here is the query that does that:
SELECT DISTINCT logdate, User AS ReportUser
FROM table
WHERE appname='abcd1234' AND logdate >=DATE-30
I have tried putting COUNT() around User but it says selected non-aggregate values must be part of the associated group.
Any idea how I can get this query to just show like row for the past 30 days and the count of distinct users?
This will be the right approach for that.
Never use
DINTINCTin Teradata. It always slows down your query performance. UseGROUP BYinstead.CORRECTION In Teradata 13 the optimizer is able to determines which version is more efficient, based on statistics. This can be found in the Release Summary for Teradata 13 under “Group By and DISTINCT Performance Equivalence”. – http://www.info.teradata.com/edownload.cfm?itemid=083440012 (PDF)