SQL 상용 어구 DQL 언어
표 조회
다 표 조회
수직 합병
하위 조회
연결
select
단일 테이블 조회
select * from students; -- students
select stuid,name,age from students; -- students stuid,name,age
select name as ,age ,stuid from students; -- ,as
select * from students where stuid = 20; -- students stuid 20
select * from students where stuid > 20; -- students stuid 20
select * from students where stuid <> 20; -- students stuid 20
select * from students where stuid != 20; -- students stuid 20
select * from students where age>10 and gender='f'; -- students 10
select * from students where age >= 20 and age <= 30; -- students 20 30
select * from students where age between 20 and 30; --
select * from students where name like 's%'; -- students name s
select * from students where name like '%yu%'; -- students name yu
select distinct age from students ; -- students age ,
select * from students where classid is null; -- students classid
select * from students where classid is not null; -- students classid
select count(stuid) from students; -- students stuid
select max(age) from students; -- students
select min(age) from students; -- students
select avg(age) from students; -- students
select gender,avg(age) as from students group by gender; -- students ,
select classid,avg(age) as from students group by classid having classid >3; -- students classid 3 , classid
select classid,gender,avg(age) from students group by classid,gender; -- students classid gender 。
select * from students order by age desc; -- students , age ,
select * from students order by -classid desc; -- students , classid , null ,
select classid,sum(age) from students group by classid order by -classid desc; -- students , classid ,
select classid,sum(age) from students group by classid order by -classid desc limit 3; -- students , classid , ,
select classid,sum(age) from students group by classid order by -classid desc limit 2,3; -- students , classid , ,
select * from students where classid in (1,3,5); -- students classid 1,3,5
다 중 표 조회
수직 합병
select stuid,name,age,gender from students union select * from teachers; -- stuid,name,age,gender
select * from teachers union all select * from teachers; -- , , all
select * from students cross join teachers; -- , ,
select * from students inner join teachers on students.teacherid=teachers.tid; -- ID id ,
select s.stuid,s.name,s.age,t.tid,t.name,t.age from students as s inner join teachers as t on s.teacherid=t.tid; -- id, , id, , , , , ID ID
select s.stuid,s.name,s.age,t.tid,t.name,t.age from students as s left outer join teachers as t on s.teacherid=t.tid; -- , id, , id, , null,
select s.stuid,s.name,s.age,t.tid,t.name,t.age from students as s right outer join teachers as t on s.teacherid=t.tid; -- , id, , id, , null,
select s.stuid,s.name student_name,s.age student_age,t.tid,t.name teacher_name,t.age teacher_age from students as s inner join teachers as t on s.teacherid=t.tid and s.age > 30; -- id, , id, , , , , ID ID , 30
select s.stuid,s.name,s.age,t.tid,t.name,t.age from students as s left outer join teachers as t on s.teacherid=t.tid where t.tid is null; -- , tid
select s.stuid,s.name,s.age,t.tid,t.name,t.age from students as s right outer join teachers as t on s.teacherid=t.tid where s.teacherid is null; -- , teacher
select s.stuid,s.name,s.age,t.tid,t.name,t.age from students as s full outer join teachers as t on s.teacherid=t.tid; -- , mysql
select s.stuid,s.name,s.age,t.tid,t.name,t.age from students as s left outer join teachers as t on s.teacherid=t.tid union select s.stuid,s.name,s.age,t.tid,t.name,t.age from students as s right outer join teachers as t on s.teacherid=t.tid ; --mysql , ,
select * from (select s.stuid,s.name s_name,s.teacherid,t.tid,t.name t_name from students s left outer join teachers t on s.teacherid=t.tid union select s.stuid,s.name,s.teacherid,t.tid,t.name from students as s right outer join teachers as t on s.teacherid=t.tid) as a where a.teacherid is null or a.tid is null; --
select st.name,co.course,sc.score from students as st inner join scores as sc on st.stuid=sc.stuid inner join courses as co on sc.courseid=co.CourseID; -- ID ID , id , , ,
합 쳐 진 표 데이터 형식 과 필드 의 수량 이 같 습 니 다.
하위 조회
select * from students where age >(select avg(age) from students); -- select
연결
seletct e.name,l.name from emp as e left join emp as l on e.leaderid=l.id; -- , ID ID
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
다양한 언어의 JSONJSON은 Javascript 표기법을 사용하여 데이터 구조를 레이아웃하는 데이터 형식입니다. 그러나 Javascript가 코드에서 이러한 구조를 나타낼 수 있는 유일한 언어는 아닙니다. 저는 일반적으로 '객체'{}...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.