테이블의 CRUD

4164 단어 데이터베이스
  (Create)、    (Retrieve)、  (Update)、  (Delete)
---------------      --------------
 .   insert into
insert into ta_name[  ,      ] values(  ),...


 .  update
update    set       =     ,...
	[where   ]
	[limit]

create table tt20(
	id int comment '  ',
	name varchar(10) not null
);

insert into tt20 values(1,'lisi'),(2,'wang'),(3,'mr.S');

update tt20 set id= 4; #    

update tt20 set id=5 where name = 'lisi';#   name lisi id=5;

update tt20 set id=4 limit 1;#      

 .   delete

delete from     
	[where   ] #  where       ,      

truncate table          #        0;

 .  

select *        。

1.select [distinct(  )] * | (  ) from   ;


create table student(
	id int(2) zerofill primary key auto_increment comment '      ,  100   ',
	name varchar(10),
	chinese decimal(4,1) default 0.0 not null,
	english decimal(4,1) default 0.0 not null,
	math decimal(4,1) default 0.0 not null
);

insert into student values
	(1,'lisi',89.0,78.0,90.0),
	(2,'tang',67.0,98.0,56.0),
	(3,'sun',87.0,78.0,77.0)
	;

insert into student(name,chinese,english,math) values
	('lao',88.0,98.0,90.0),
	('hong',82.0,84.0,67.0)
	;

insert into student values
	(6,'ru',55.0,85.0,45.0),
	(7,'  ',75.0,65.0,30.0)
	;

select id,name,chinese from student;

select distinct math from student; #    

select chinese+english+math from student;#    

2.as

select chinese+english+math as '  ' from student; #           as    

3.where    (and      or)
    tang         60% 

select name,(chinese+english+math)*1.6
	from student
	where name like 'tang%';#like     
 
        90           
select name,english from student
	where english > 90;

   li      >85           

select name,(chinese+english+math) from student
	where name like 'li%' and math > 85;

      200                  

select id,name from student
	where (chinese+math+english)>200 and
	math < chinese and
	name like 'tang';

       84-90     

select id,name from student
	where engish>=84 and english <=90;

4.between and

select id,name from student 
	where english between 84 and 90;# between..and..    

      200           

select name,(english+chinese+math) as total from student
	where total >200; #   where            


5.order by                  

select  [distinct(  )]    ...
	from   
	[where   ]
	order by    asc(  ) | desc;

      200           ,          

select name,(english+chinese+math) as total from student
	where (english+chinese+math) >200
	order by total;

6.    
select...
	[where   ]
	limit     ,    

        ,    3   ,     。

select * from student limit 3,3; #   4,5,6

7.    
count(  |*)    null
sum()
avg()
max()
min()
select count(math) from student; #7
select count(*) from student; #7

alter table student modify math decimal(4,1) default 0.0;

insert into student values(8,'opo',89,99,null);

select count(math) from student; #7
select count(*) from student; #8

8.     group by
     having

select   ..
	from   
	group by   

              
select avg(  ),max(  )
	from   
	group by   ;

select avg(sal),max(sal),deptno
	from emp
	group by deptno;

         2000            
select avg(sal) as avg_sal,deptno
	from emp
	group by deptno having avg_sal <2000;

--------------------    ----------------

             

        ,         

        (1,2)(3,4) = [(1,3),(1,4),(2,3),(2,4)]
select ename,sal,dname
	from emp,dept
	where emp.deptno = dept.deptno;#  


      10     ,       

select dname,ename,sal
	from emp,dept
	where emp.deptno = dept.deptno
	and emp.deptno = 10;#                  deptno

-------------------   ---------------
   SMITH           ,    

select ename,empno
	from emp
	where empno=(select deptno
		from emp
		where ename = 'SMITH');#   SMITH

select deptno
	from emp
	where ename = 'SMITH';

-------------------  ----------------
  :   

create index empno_index on emp(empno); #  emp empno      empno_index   

       :
1.                   
2.                  
3.                
4.     where            

-------------------  -----------------

좋은 웹페이지 즐겨찾기