05 4 查詢練習2

2022-05-13 20:40:33 字數 2872 閱讀 1678

departments 部門表

--dept_emp 部門員工表

--dept_manager 部門主管表

--employees 雇員表

--salaries 薪水表

--titile 職稱表

--* 查詢統計公司員工數量、男員工數量、女員工數量

select

count(employees.emp_no) from

employees;

select

count(employees.emp_no) from employees where gender ='m

';select

count(employees.emp_no) from employees where gender ='f

'; --

* 查詢員工最新薪水 (分頁,第一頁,每頁50行)

--select * from student limit ((當前頁數 - 1) * 每頁行數), 行數

select

*from salaries where to_date =

'9999-01-01

' limit 0,50;

--* 查詢部門列表需顯示當前主管名字

select departments.dept_no as

'部門編號

',departments.dept_name as

'部門名稱

',employees.first_name as'名字

',employees.last_name as'姓氏

'from departments,employees,dept_manager where departments.dept_no = dept_manager.dept_no and employees.emp_no = dept_manager.emp_no and dept_manager.to_date =

'9999-01-01';

--* 查詢 lillian haddadi的詳細資訊,及薪水調薪記錄 以及擔任某部門主管的詳細資訊

select

*from employees where employees.first_name =

'lillian

'and employees.last_name =

'haddadi';

--下面的語句為啥會卡死程式?

--因為有一張不必要查詢的表,相當於做了交叉鏈結查詢,會查詢到巨大乘積的資料,把from後面的salaries去掉就能查到了

--即使修改正確以後,上下兩句的效率也相差很多,下面的查詢語句明顯執行得慢很多

select salaries.emp_no,salaries.from_date,salaries.to_date,salaries.salary from salaries,employees where employees.first_name =

'lillian

'and employees.last_name =

'haddadi

'and employees.emp_no =

salaries.emp_no;

select salaries.emp_no,salaries.from_date,salaries.to_date,salaries.salary from salaries where salaries.emp_no in (select employees.emp_no from employees where employees.first_name =

'lillian

'and employees.last_name =

'haddadi');

--沒有找到擔任主管的資訊?可能是找職稱?

select

*from titles where titles.emp_no =

10019

;select

*from dept_manager,employees where employees.first_name =

'lillian

'and employees.last_name =

'haddadi

'and employees.emp_no =

dept_manager.emp_no; --

* 查詢 shahaf famili的詳細資訊,及薪水調薪記錄 以及擔任某部門主管的詳細資訊

select

*from employees where employees.first_name =

'shahaf

'and employees.last_name =

'famili';

select salaries.emp_no,salaries.from_date,salaries.to_date,salaries.salary from salaries,employees where employees.first_name =

'shahaf

'and employees.last_name =

'famili

'and employees.emp_no =

salaries.emp_no;

select

*from dept_manager,employees where employees.first_name =

'shahaf

'and employees.last_name =

'famili

'and employees.emp_no = dept_manager.emp_no;

練習 LCA練習2

1.bzoj1787緊急集合 找一點使這一點到三個點有最短距離 列舉三個兩兩lca即可 include include include include include define inf 999999999 using namespace std int n,q,cnt int deep 5000...

MySQL 2 單錶查詢(練習1)

mysql uroot p密碼 show databases 檢視所有資料庫 use db1 使用其中乙個資料庫create table dept deptno int primary key,dname varchar 14 部門名稱 loc varchar 13 部門位址 insert into...

查詢練習(四)

常見約束 1.not null 非空 2.unique 唯一,可以出現乙個null 3.primary key 主鍵,唯一,非空 4.foreign key 外來鍵,定義主表和從表的關聯關係 從企業管理器看!5.check 檢查,強制資料必須滿足定義的條件,如 sal int check sal 2...