troubleshooting Question

count number of records for each day

Avatar of Big Monty
Big MontyFlag for United States of America asked on
SQLMicrosoft SQL Server
46 Comments1 Solution57 ViewsLast Modified:
I'm attempting to create a query that'll return to me the number of records for a given date range.
[code]
declare @startDate datetime = '2020-01-01';
declare @endDate datetime = '2020-04-01';

select Date_Added, count( BookingID ) as Total
from bookings
where In_Jail = 1 and Date_Added <= @endDate
group by Date_Added
order by 1 desc;
[/code]

In_Jail tells me if the inmate is still in jail, 1 = true, 0 = false. Right now it's giving me the total number per day, and what I want is to have it tell me the total amount of inmates actively in the jail.

I think I'm pretty close, but am having trouble getting over that last piece, so any help is greatly appreciated!
ASKER CERTIFIED SOLUTION
Dustin Saunders
Co-Founder and Chief Architect

Our community of experts have been thoroughly vetted for their expertise and industry experience.

Top Expert 2016

The Distinguished Expert awards are presented to the top veteran and rookie experts to earn the most points in the top 50 topics.

Join our community to see this answer!
Unlock 1 Answer and 46 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 46 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros