473,406 Members | 2,620 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

counting distinct posts by a users within the past 10 days - SQL2005

Hey gang, any help will be apprecited. I am trying to do a simple count of all posts to a message board from a few particular users within the past 10 days.

I know the usernames and number of days that i want to query (10) and I want the output to display as follows....
Manager PostCount
user1 1
user2 14
user3 20
___________________

The query i have is but below but there is two problems with it. They are not being grouped but rather outputing lineitem AND the DATEADD criteria does not seem to affect the result.

Expand|Select|Wrap|Line Numbers
  1. SELECT     PostAuthor, COUNT(PostAuthor) AS PM_Count
  2. FROM         cs_Posts
  3. GROUP BY PostAuthor, PostDate
  4. HAVING      (PostDate = DATEADD(d, - 10, GETDATE())) AND (PostAuthor = N'dclecompte') OR
  5.                       (PostAuthor = N'haley') OR
  6.                       (PostAuthor = N'clapoint')
  7. ORDER BY PostDate DESC, PostAuthor
I am a new guy so I really do appreciate any help that you can provide.
Dec 26 '07 #1
2 1146
TRY THIS

Expand|Select|Wrap|Line Numbers
  1. SELECT     COUNT(PostAuthor) AS PM_Post_Count, PostAuthor
  2. FROM         dbo.cs_Posts
  3. WHERE     (PostDate = DATEADD(d, - 10, GETDATE())) OR
  4.                       (PostAuthor = N'haley') OR
  5.                       (PostAuthor = N'clapoint') OR
  6.                       (PostAuthor = N'dclecompte')
  7. GROUP BY PostAuthor

Hey gang, any help will be apprecited. I am trying to do a simple count of all posts to a message board from a few particular users within the past 10 days.

I know the usernames and number of days that i want to query (10) and I want the output to display as follows....
Manager PostCount
user1 1
user2 14
user3 20
___________________

The query i have is but below but there is two problems with it. They are not being grouped but rather outputing lineitem AND the DATEADD criteria does not seem to affect the result.

Expand|Select|Wrap|Line Numbers
  1. SELECT     PostAuthor, COUNT(PostAuthor) AS PM_Count
  2. FROM         cs_Posts
  3. GROUP BY PostAuthor, PostDate
  4. HAVING      (PostDate = DATEADD(d, - 10, GETDATE())) AND (PostAuthor = N'dclecompte') OR
  5.                       (PostAuthor = N'haley') OR
  6.                       (PostAuthor = N'clapoint')
  7. ORDER BY PostDate DESC, PostAuthor
I am a new guy so I really do appreciate any help that you can provide.
Dec 26 '07 #2
amitpatel66
2,367 Expert 2GB
TRY THIS

Expand|Select|Wrap|Line Numbers
  1. SELECT     COUNT(PostAuthor) AS PM_Post_Count, PostAuthor
  2. FROM         dbo.cs_Posts
  3. WHERE     (PostDate = DATEADD(d, - 10, GETDATE())) OR
  4.                       (PostAuthor = N'haley') OR
  5.                       (PostAuthor = N'clapoint') OR
  6.                       (PostAuthor = N'dclecompte')
  7. GROUP BY PostAuthor
Is it working now or still facing an issue??
Dec 27 '07 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

6
by: Ike | last post by:
How can I make a query such that in the "WHERE" part of my clause, I want to put something to the effect that, say, X days have elapsed since a given date. For example, suppose in my table, I have...
2
by: Mark Jerzykowski | last post by:
Hi, I have a log table which contains the fields log_time (DATETIME) and session_id (VARCHAR). Using these 2 columns I want to be able to SELECT the number of users who have been online during...
5
by: Cam Bevis | last post by:
I'm having trouble getting my head around this, and no one in the groups has posted exactly the problem. The table below tracks site traffic across a network. There is 1 row per pageview and...
2
by: calan | last post by:
Having a brainfart.... I need a query that returns a record count, based on two distinct fields. For example: Order Revision Customer 001 1 Bob...
1
by: nfrodsham | last post by:
In Microsoft's help literature, it states: "You can filter out non-unique rows by using the DISTINCT option of an aggregate function" I am trying to do this in Access 2003 with the COUNT...
6
by: MLH | last post by:
I'm tired of reading the fine print! Too many registrars out there. So I'm asking this group for a little help. I'm looking for a Registrar who will do an honest day's work for a fair price. I'm...
2
by: jason.teen | last post by:
Hi I have this scenario: group | id | value --------------------------------- x | location | QLD x | location | NSW x | location | VIC x | ...
1
LMHelper
by: LMHelper | last post by:
Ok I am creating a new database for LM. One that will keep track of our licenses for over 400 users. We already have a database with the users information like name, location, telephone number,...
2
by: vspsdca | last post by:
Hi, I'm quite new to the world of VBA so any help you could extend will help me a lot with my project. I have a database of Change Requests from our users. I have two date boxes, one is Date...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.