sql語句的練習

2021-09-26 09:25:18 字數 2215 閱讀 7130

例:

create table department(

id int,

name varchar(50)

);

unian是將兩個查詢的結果合在一起顯示

unian all是在顯示的時候將重複的資料剔除然後再顯示結果。

例:

select * from employee_chain union select * from employee_usa;

select e.id,e.name as '員工名',d.name as '部門' from employee e,department d where  e.depno = d.id  ;
select e.id,e.name as '員工名',d.name as '部門' from employee e inner join department d on e.depno = d.id  ;

左連線**:

select e.id,e.name as '員工名',d.name as '部門'  from employee e  left outer join department d on e.depno = d.id  ;
select e.id,e.name as '員工名',d.name as '部門'  from employee e  right outer join department d on e.depno = d.id 

新建兩個表

create  table depart(

depno int primary key,

name varchar(50),

location varchar(50),

setuptime timestamp

);

create table emp(

empno int primary key,

ename varchar(50),

job varchar(50),

mgr int,

hiredate date,

sal decimal(7,2),

comm decimal(7,2),

depno int,

constraint fk_emp_depart foreign key(depno) references depart(depno)

);

constraint fk_emp_depart foreign key(depno) references depart(depno)

這句語句是指只能選擇選擇表depart裡的depno有的值。

子查詢**:

select * from emp where sal> (select sal from emp where ename='林同學' )
結果:

兩個表之中的聯絡:

select empno,sal,name,location from emp ,depart where emp.depno=depart.depno and emp.ename='劉同學';

SQL語句練習

建立一張表,記錄 呼叫員的工作流水,記錄呼叫員編號,對方號碼,通話開始時間,結束時間。建表,插資料等都自己寫出sql 要求 輸出所有資料中通話時間最長的5條記錄。輸出所有資料中撥打長途號碼 對方號碼以0開頭 的總時長 輸出本月通話時長最多的前三個呼叫員的編號 輸出本月撥打 次數最多的前三個呼叫員的編...

SQL 語句練習

mysql select from persons limit 5 oracle select from persons where rownum 5 select from persons where name like l select from persons where name not l...

SQL語句練習

1 把兩張 的資料抽取出來放到另外一張 中 1 pt表 role id int pt int 2 season score表 role id int season score int 3 player表 role id int pt int season score int count int 4 ...