从SQL数据库HTML获取统计信息

时间:2017-07-18 08:58:18

标签: html sql

给定一个包含表“TAB1”的数据库“firstdb”。这张表只不过是可以显示如下的学生信息

ID   Last Name    First Name    Date of Birth      School             Specialty    Sex
01    yves          marco        03/03/2000      la roccade school      letter     man
02    marchal       zeko         05-12-1999      johara school          letter     man
03    ghisil        maria        15-03-2000      johara school          science    women
04    belbali       john         30-10-1999      lever school           science    man
05    santa         sofi         04-05-2000      la roccade school      science    women
06    yves          don          16/04/2000      la roccade school      lette      man

如果使用这些数据并根据一些冒号提取统计数据:“学校,专业,性别”,其结果应如下:

School          Specialty       Sex       number
la roccade school   letter      man         02
la roccade school    letter     women       00
la roccade school   science     man         00
la roccade school   science     women       01
johara school       letter      man         01
johara school       letter      women       00
johara school       science     man         00
johara school       science     women       01
lever school        letter      man         00
lever school        letter      women       00
lever school        science     man         01
lever school        science     women       00

PS:数据量不固定。哪里可以改变。

1 个答案:

答案 0 :(得分:1)

您是否只是在寻找查询以获得所需的结果?这应该有效:

SELECT
    School,
    Specialty,
    Sex,
    COUNT(ID) AS Number
FROM TAB1
GROUP BY
    School,
    Specialty,
    Sex;