I have a table where records for a user are stored
我有一个存储用户记录的表。
This includes 2 columns applied_date.
,js_id.
这包括2列applied_date.、js_id。
now i have to count js_id have applied to number of job this month.
现在我要数一数这个月js_id申请了多少工作。
3 个解决方案
#1
0
Select count(js_id) from yourtable WHERE DATEDIFF( m, applied_date, GETDATE() ) = 0
#2
2
Something like:
喜欢的东西:
SELECT COUNT(js_id), MONTH(applied_date)
FROM table
GROUP BY MONTH(applied_date)
#3
2
For a specific month (given a date),
特定月份(给定日期),
DECLARE @date SMALLDATETIME = '20120105'; -- for January, also could use CURRENT_TIMESTAMP
-- the above could also be a stored procedure parameter
SET @date = DATEADD(MONTH, DATEDIFF(MONTH, 0, @date), 0);
SELECT COUNT(js_id)
FROM dbo.[table_name]
WHERE applied_date >= @date
AND applied_date < DATEADD(MONTH, 1, @date);
#1
0
Select count(js_id) from yourtable WHERE DATEDIFF( m, applied_date, GETDATE() ) = 0
#2
2
Something like:
喜欢的东西:
SELECT COUNT(js_id), MONTH(applied_date)
FROM table
GROUP BY MONTH(applied_date)
#3
2
For a specific month (given a date),
特定月份(给定日期),
DECLARE @date SMALLDATETIME = '20120105'; -- for January, also could use CURRENT_TIMESTAMP
-- the above could also be a stored procedure parameter
SET @date = DATEADD(MONTH, DATEDIFF(MONTH, 0, @date), 0);
SELECT COUNT(js_id)
FROM dbo.[table_name]
WHERE applied_date >= @date
AND applied_date < DATEADD(MONTH, 1, @date);