Quantcast
Channel: Microsoft SQL Server
Viewing all articles
Browse latest Browse all 4871

How can I select DISTINCT while also returning dates?

$
0
0

I am trying to build a simple pivot table report for our purchasing department that will show how many unique customers purchased items within a given date range.

If I build a view using DISTINCT, it works perfectly until I select the posted date. Once I do that, it returns how many total customers purchased that item within the date range, but if one customer bought something twice, then they get counted as 2 which is throwing off my results.

I need for them to have the date as an available filter in the pivot table, so my question is:

Is there an alternate method to go about this that would select only the unique customer accounts that purchased that item while still allowing for date selection so that they can filter the date field?

Here's what returns the proper number/customer count:

SQL
SELECTDISTINCTTOP(100)PERCENTPS.[Customer...

Viewing all articles
Browse latest Browse all 4871

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>