create table Emp
(
 eid char(20) primary key,
 ename char(20),
 age integer check (age > 0),
 did char(20),
 salary float,
)
create table Dept
(
 did char(20) primary key,
 dname char(20),
 mgr_did char(20), 
)
alter table Emp add constraint fk_emp_did foreign key (did) references Dept(did)
alter table Dept add constraint fk_dept_mgrdid foreign key (mgr_did) references Emp(eid)

题目:写出一条SQL语句,查询工资高于10000,且与他所在部门的经理年龄相同的职工姓名。

select * from Emp a, Dept b, Emp c where a.did = b.did and b.mgr_did = c.eid and a.salary > 10000 and a.age = c.age;

题目:写出一条SQL语句,查询工资高于10000,且与他所在部门的经理年龄相同的职工姓名。的更多相关文章

  1. 写出一条Sql语句:取出表A中第31到第40记录(SQLServer,以自动增长的ID作为主键,注意:ID可能不是连续的。

    答:解1:  select top 10 * from A where id not in (select top 30 id from A) 解2:  select top 10 * from A ...

  2. 写出一条Sql语句:取出表Customer中第31到第40记录(SQLServer,以自动增长的Id作为主键,注意:Id可能不是连续的。

    select top 10 * from (select ROW_NUMBER() over(order by Id) as rows,* from Customer) as C where C.ro ...

  3. 写出一条SQL语句:取出表A中第31到40行记录(SQLserver,以自增长的ID作为主键,注意: 一条Sql语句:取出表A中第31到第40记录

    解1: select top 10 * from A where id not in (select top 30 id from A) 解2: select top 10 * from A wher ...

  4. 理解SQL原理,写出高效的SQL语句

    我们做软件开发的,大部分人都离不开跟数据库打交道,特别是erp开发的,跟数据库打交道更是频繁,存储过程动不动就是上千行,如果数据量大,人员流动大,那么我们还能保证下一段时间系统还能流畅的运行吗?我们还 ...

  5. 使用一条sql语句查询多表的总数

    SELECT sum(列名1) 列名1,sum(列名2) 列名2,sum(列名3) 列名3 FROM ( SELECT count(*) 列名1, 列名2, 列名3 FROM 表1 -- WHERE ...

  6. 一条SQL语句查询两表中两个字段

    首先描述问题,student表中有字段startID,endID.garde表中的ID需要对应student表中的startID或者student表中的endID才能查出grade表中的name字段, ...

  7. 子查询注意这几点, 就可以写出好的sql语句

    执行sql时子查询的语句一般优先执行 理论上多表查询效率是高于子查询(根据子查询不值一个查询语句可能会有多个from但是多表查询只产生一个from), 但是在oracle中子查询效率一般会高于多表查询

  8. mysql 按类别之用一条SQL语句查询出每个班前10名学生数据

    select * from 学生信息表 a where 10 >  (select count(*) from 学生信息表 where 班级ID = a.班级ID and 班内名次 > a ...

  9. 分享最近写的 两条sql语句

    1. 搭建基本环境 插入测试数据 insert into jgdm (jgdm,jgmc)  values('12300000000','河南省');insert into jgdm (jgdm,jg ...

随机推荐

  1. Vue.js 实战教程(附demo)

    在实战之前,你需要对vuejs的基础语法有一定的了解,可以通过以下几个途径进行学习: vue.js官方文档:https://cn.vuejs.org/v2/guide/index.html vue.j ...

  2. 【解决】虚拟windows7无法安装VMware Tools

    VMware安装虚拟windows7,在虚拟windows7上安装VMware Tools 报错VMware Alias Manager and Ticket 服务失败. Windows 无法启动 V ...

  3. wampserver64 apache2.4版本局域网互相访问总结

    wampserver64  apache2.4版本局域网互相访问总结 背景:在我的电脑上给算法组开发了一个工具,需要在局域网环境下其他同事都能访问到,搞了一下午终于搞定,于是整理了这篇文档,给其他同行 ...

  4. mysql 8.0.11安装教程

    安装环境:win7 1. 下载安装包 下载地址:https://dev.mysql.com/downloads/file/?id=476233 2. 解压zip包 3. 初始化my.ini 创建my. ...

  5. C#可空类型 T?

    可空类型概述 可空类型具有以下特性: 可空类型表示可被赋值为 null 值的值类型变量.无法创建基于引用类型的可空类型.(引用类型已支持 null 值.). 语法 T? 是 System.Nullab ...

  6. Stack (30)(模拟栈,输出中间数用set)

    Stack is one of the most fundamental data structures, which is based on the principle of Last In Fir ...

  7. codewars贪吃蛇算法题目

    有这样一个题目: Given an n x n array, return the array elements arranged from outermost elements to the mid ...

  8. linux命令的学习随笔

    getconf PAGE_SIZE //获取内存分页的大小alias vi='vim'//临时生效vi /root/.bashrcwhereis ls输出重定向> >> 2> ...

  9. C++——自然数求和

    代码如下: #include <iostream> using namespace std; int main() { int a,sum=; for(int i=;i<=;i++) ...

  10. 14_Web服务器-并发服务器

    1.服务器概述 1.硬件服务器(IBM,HP): 主机 集群 2.软件服务器(HTTPserver Django flask): 网络服务器,在后端提供网络功能逻辑处理数据处理的程序或者架构等 3.服 ...