Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Count Number of rows per day in Sybase database

Posted on 2004-09-08
4
Medium Priority
?
410 Views
Last Modified: 2008-02-26
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
Comment
Question by:abidar
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 15

Accepted Solution

by:
jdlambert1 earned 1000 total points
ID: 12012244
SELECT Count(*)
FROM YourTableName
WHERE YourDateColumn >= DateAdd(d,-7,GetDate())
0
 
LVL 15

Expert Comment

by:jdlambert1
ID: 12012264
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

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Your data is at risk. Probably more today that at any other time in history. There are simply more people with more access to the Web with bad intentions.
This article shows how to get a list of available printers for display in a drop-down list, and then to use the selected printer to print an Access report or a Word document filled with Access data, using different syntax as needed for working with …
Video by: Steve
Using examples as well as descriptions, step through each of the common simple join types, explaining differences in syntax, differences in expected outputs and showing how the queries run along with the actual outputs based upon a simple set of dem…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…

661 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question