Please start any new threads on our new site at http://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

Our new SQL Server Forums are live! Come on over! We've restricted the ability to create new threads on these forums.

SQL Server Forums
Profile | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 SQL Server 2008 Forums
 Transact-SQL (2008)
 Help with count
 Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

Diablos
Starting Member

10 Posts

Posted - 10/29/2015 :  12:57:23  Show Profile  Reply with Quote
Hi
I'm having problems with the following count:
Here is my data
Bus Starting Date End Date
4561 2015-10-26 00:00:00.000 2015-10-26 00:00:00.000
4614 2015-10-28 00:00:00.000 2015-10-28 00:00:00.000
4443 2015-10-26 00:00:00.000 2015-10-28 00:00:00.000
4521 2015-10-27 00:00:00.000 2015-10-27 00:00:00.000
4615 2015-10-28 00:00:00.000 2015-10-28 00:00:00.000

I want to know the total number of bus active based on the start and end by day,the result should be
- day 26 i have 2 bus active (4561 and 4443)
- day 27,the result is 2 (4521 and 4443)
- day 28 the result is 3 (4614,4443,4615).
i've tried with between but to no result.
Thanks for your help!!


vedjha
Posting Yak Master

India
228 Posts

Posted - 06/18/2016 :  12:12:05  Show Profile  Visit vedjha's Homepage  Reply with Quote

select count (bus), bus from table_name where EndDate between 'mm/DD/yy' and 'mm/DD/yy' group by bus having count (bus)>0

http://kiransoftech.com
Go to Top of Page

vedjha
Posting Yak Master

India
228 Posts

Posted - 06/18/2016 :  12:12:06  Show Profile  Visit vedjha's Homepage  Reply with Quote

select count (bus), bus from table_name where EndDate between 'mm/DD/yy' and 'mm/DD/yy' group by bus having count (bus)>0

http://kiransoftech.com
Go to Top of Page
  Previous Topic Topic Next Topic  
 Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.02 seconds. Powered By: Snitz Forums 2000