• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 419
  • Last Modified:

Count Number of rows per day in Sybase database

I have a very big table in my sybase database.
I need to count the number of rows for the last 7 days.

Could you please help me with a simple sql script.
This query should check the last date and calculate the number of rows for the 7 previous date.

Thanks a lot
Abdel
0
abidar
Asked:
abidar
  • 2
1 Solution
 
jdlambert1Commented:
SELECT Count(*)
FROM YourTableName
WHERE YourDateColumn >= DateAdd(d,-7,GetDate())
0
 
jdlambert1Commented:
GetDate() is the T-SQL function to return the current system time. DateAdd is the function to add or subtract from datetime values. So the query above subtracts 7 days from the current date, then checks your date column to see if it's later than that. Anything counted will be in the last 7 days. With a lot of records, it will help to create an index on the date column like this:

CREATE INDEX index_on_MyDateColumn ON MyTableName(MyDateColumn)
0

Featured Post

The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now