Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Simple SQL Select issue
Message
General information
Forum:
Visual FoxPro
Category:
Databases,Tables, Views, Indexing and SQL syntax
Environment versions
Visual FoxPro:
VFP 9
OS:
Windows 7
Network:
Windows 2003 Server
Database:
Visual FoxPro
Application:
Desktop
Miscellaneous
Thread ID:
01499700
Message ID:
01499702
Views:
50
>I think it must be Friday... as my mind has gone to lunch this afternoon. I know its only Thursday :)
>
>I have a table with multiple records for employees and dates...
>ie epkey 15, might have 4 records on date 1, 3 on date 2, etc...
>
>I don't want to count the records, I want to count the dates...
>ie if i just looking at date range between date 1 and 2, I don't want a count of the records, rather a count of the unique dates, ie 2 not 7.
>
>A simple Select like this doesn't work.
>
>Sele epkey, count(date) from histwkrd where date between date1 and date2 group by epkey
>
>would return based on the above data, 7 where I would only to see the distinct dates ie, count those, not all the records.
>
>I know I can do this with two queries, but is there a better way?
>
>TIA,
>Mike

Mike,

You can use COUNT (distinct date), but using 2 queries may be you best bet.
Take a look at this blog post
http://blogs.msdn.com/b/sqlqueryprocessing/archive/2008/09/22/distinct-aggregation-considered-harmful.aspx
and you can also check
http://www.windowsitpro.com/article/database-administration/T-SQL-Deep-Dives-Creating-Queries-That-Work-and-Perform-Well/6.aspx
If it's not broken, fix it until it is.


My Blog
Previous
Reply
Map
View

Click here to load this message in the networking platform