SQL COUNT在两个不同列之间的日期之间 [英] SQL COUNT between dates in two different column
本文介绍了SQL COUNT在两个不同列之间的日期之间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我们有这个表:
STUDENT | START | END
1 |1998-1-1 |2001-1-1
2 |1999-1-1 |2001-1-1
3 |2000-1-1 |2004-1-1
4 |2000-1-1 | NULL
我想做的是:
计数开始和结束日期之间的学生人数
Count number of students between start and end dates!
推荐答案
看起来你需要使用基本的 COUNT
aggregate:
Looks like you need to use a basic COUNT
aggregate:
SELECT COUNT(Student)
FROM YourTable
WHERE Start >= @Start
AND End <= @End
ve分别在开始和结束日期字段周围使用了> =和<=。随意更改为>或<如所须。从您的问题中不清楚您是想在特定字段之间,还是要检查这两个字段之间的范围。
I've used >= and <= respectively around the start and end date fields. Feel free to change to > or < as needed. It was unclear from your question whether you wanted between a specific field or if you were checking for a range between those two fields.
这篇关于SQL COUNT在两个不同列之间的日期之间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文