zoukankan      html  css  js  c++  java
  • SQL练习题14:从titles表获取按照title进行分组,每组个数大于等于2,给出title以及对应的数目t。

    题目:

    从titles表获取按照title进行分组,每组个数大于等于2,给出title以及对应的数目t。
    CREATE TABLE IF NOT EXISTS "titles" (
    `emp_no` int(11) NOT NULL,
    `title` varchar(50) NOT NULL,
    `from_date` date NOT NULL,

    `to_date` date DEFAULT NULL);
    如插入:

    INSERT INTO titles VALUES(10001,'Senior Engineer','1986-06-26','9999-01-01');
    INSERT INTO titles VALUES(10002,'Staff','1996-08-03','9999-01-01');
    INSERT INTO titles VALUES(10003,'Senior Engineer','1995-12-03','9999-01-01');
    INSERT INTO titles VALUES(10004,'Engineer','1986-12-01','1995-12-01');
    INSERT INTO titles VALUES(10004,'Senior Engineer','1995-12-01','9999-01-01');
    INSERT INTO titles VALUES(10005,'Senior Staff','1996-09-12','9999-01-01');
    INSERT INTO titles VALUES(10005,'Staff','1989-09-12','1996-09-12');
    INSERT INTO titles VALUES(10006,'Senior Engineer','1990-08-05','9999-01-01');
    INSERT INTO titles VALUES(10007,'Senior Staff','1996-02-11','9999-01-01');
    INSERT INTO titles VALUES(10007,'Staff','1989-02-10','1996-02-11');
    INSERT INTO titles VALUES(10008,'Assistant Engineer','1998-03-11','2000-07-31');
    INSERT INTO titles VALUES(10009,'Assistant Engineer','1985-02-18','1990-02-18');
    INSERT INTO titles VALUES(10009,'Engineer','1990-02-18','1995-02-18');
    INSERT INTO titles VALUES(10009,'Senior Engineer','1995-02-18','9999-01-01');
    INSERT INTO titles VALUES(10010,'Engineer','1996-11-24','9999-01-01');
    INSERT INTO titles VALUES(10010,'Engineer','1996-11-24','9999-01-01');

    思路:

    看到分组要用GROUP BY。

    程序:

    SELECT title, COUNT(title) AS t
    FROM titles
    GROUP BY title
    HAVING t >= 2
    
  • 相关阅读:
    java bio 之聊天室
    自定义gradle plugin
    gradle build 找不到tools.jar 解决方法
    java switch case 枚举类型的反编译结果
    spring mvc 关键接口 HandlerMapping HandlerAdapter
    H5 Video 去除 下载按钮 禁用右键
    https 请求发送 例子 tls && ssl
    mac 安装mongodb
    (扫盲)DTO数据传输对象
    (扫盲)RPC远程过程调用
  • 原文地址:https://www.cnblogs.com/zhuozige/p/13709362.html
Copyright © 2011-2022 走看看