如何检索每个月的注册学生人数 [英] How to retrieve number of registered students list for each month

查看:78
本文介绍了如何检索每个月的注册学生人数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我有一张桌子来注册学生信息.我想编写查询以在单个查询中显示每个月的注册学生人数.如果有人知道这一点,请帮助我.


在此先感谢.

解决方案

在不知道表字段名称的情况下,不可能告诉您正确的查询.

我假设您已经为"RegisteredDate"提供了某种字段?遵循这些原则...

  SELECT 
    转换( CHAR ( 4 ),RegisteredDate , 100 )+ 转换( CHAR (  4 ),RegisteredDate, 120 ) AS 注册月份
    SUM(StudentId) AS  SumOfStudents
 FROM 
    学生注册
  BY 
    转换( CHAR ( 4 ),RegisteredDate , 100 )+ 转换( CHAR (  4 ),RegisteredDate, 120 )



转换将显示为[Month Year],例如"2011年6月"-您需要考虑年份,而不仅是月份部分...否则,在2010年12月和2011年12月注册的学生将全部归为一类. /blockquote>

使用"where"条件,您可以从db中检索数据

喜欢

从regusers中选择*,其中month =''jan"且status = 1

这样你就可以检索


Hi,

I have one table to register students information. I want to write query to display number of registered students for each and every month in single query. If anybody know this please help me.


Thanks in Advance.

解决方案

Without knowing your table field names, it''s impossible to tell you a correct query.

I''m assuming you''ve got some sort of field for ''RegisteredDate''? Something along these lines...

SELECT
    CONVERT(CHAR(4), RegisteredDate, 100) + CONVERT(CHAR(4), RegisteredDate, 120) AS MonthRegistered,
    SUM(StudentId) AS SumOfStudents
FROM
    StudentRegistrations
GROUP BY
    CONVERT(CHAR(4), RegisteredDate, 100) + CONVERT(CHAR(4), RegisteredDate, 120)



The conversion will display as [Month Year], e.g ''Jun 2011'' - you need to take year into account and not just the month part...otherwise students registered in Dec 2010 and Dec 2011 would all be group together.


using ''where'' condition u can retrieve the data from db

like

select * from regusers where month=''jan'' and status=1

like that u can retrieve


这篇关于如何检索每个月的注册学生人数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆