数据库,sql查询,mysql [英] database, sql query, mysql

查看:85
本文介绍了数据库,sql查询,mysql的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨 我有一张学生记录表,
我想计算特定年龄段的学生人数,并且还要增加年龄段.
输出将像
学生年龄
7 12
8 17
9 4
. .
. .
. .
28 21


解决方案

  SELECT 
    年龄,
    COUNT(StudentName) AS  [没有 名学生]
 FROM 
    TMP
  BY 
    年龄
订单  BY 
    年龄



请根据您的表结构,用列名称替换年龄"和学生姓名".


你好,

如果你的结构像
表学生栏:StudentID(主键),Name(varchar),Firstname(varchar),Dateofbirth(datetime)

然后用这个
SELECT FLOOR(DATEDIFF(day,Dateofbirth,GETDATE())/365.25)年龄,COUNT(*)AS [学生人数]来自TblEmployee GROUP BY FLOOR(DATEDIFF(day,Dateofbirth,GETDATE())/365.25);

希望它对您有用.

sanjeev


要计算指定年龄的学生人数,SQL查询为:

 选择 SUM(No_Of_Students)来自 [其中​​ Age = [您指定的年龄] 



计算指定年龄以下的学生人数:

 选择 SUM(No_Of_Students)来自 [位置(年龄= 1  OR 年龄= 3 ...  OR 年龄= [您指定的年龄] 



谢谢.


hi i have a table of students record,
i want to calculate number of students of a specific age , and also for increasing age.
the output will be like
Age No of students
7 12
8 17
9 4
. .
. .
. .
28 21


what will be the query for that, can anybody help e out?

解决方案

SELECT
    Age,
    COUNT(StudentName) AS [No of Students]
FROM
    TMP
GROUP BY
    Age
ORDER BY
    Age



Please replace "Age" and "StudentName" with the column name(s) as per your table structure.


hello ,

if your structure is like
TABLE STUDENTS COLUMNS: StudentID (primary key), Name(varchar), Firstname(varchar), Dateofbirth(datetime)

then use this
SELECT FLOOR(DATEDIFF(day,Dateofbirth , GETDATE()) / 365.25) AS AGE, COUNT(*) AS [No of Student] FROM TblEmployee GROUP BY FLOOR(DATEDIFF(day, Dateofbirth, GETDATE()) / 365.25);

hoping it will work for you.

sanjeev


For Calculating number of students of specified age the SQL Query is as :

Select SUM(No_Of_Students) From [table name] Where Age=[Your Specified Age]



And for Calculating number of students below the specified Age :

Select SUM(No_Of_Students) From [table Name] Where (Age=1 OR Age=2 OR Age=3 ... OR Age=[Your specified Age]



Thanks.


这篇关于数据库,sql查询,mysql的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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