본문 바로가기
개발/sql

mysql as,update,desc,asc,is null,or,concat,like,이중 select

by 카앙구운 2015. 8. 14.
728x90
반응형
membership

필드종류Collation보기Null기본값추가실행
int(10)UNSIGNED아니오auto_increment보기변경삭제기본인덱스고유값Fulltext
varchar(20)euckr_korean_ci아니오보기변경삭제기본인덱스고유값Fulltext
varchar(100)euckr_korean_ci아니오보기변경삭제기본인덱스고유값Fulltext
varchar(20)euckr_korean_ci아니오보기변경삭제기본인덱스고유값Fulltext
enum('M', 'F')euckr_korean_ciNULL보기변경삭제기본인덱스고유값Fulltext
dateNULL보기변경삭제기본인덱스고유값Fulltext
varchar(100)euckr_korean_ciNULL보기변경삭제기본인덱스고유값Fulltext
varchar(20)euckr_korean_ciNULL보기변경삭제기본인덱스고유값Fulltext
varchar(20)euckr_korean_ci아니오보기변경삭제기본인덱스고유값Fulltext
char(6)euckr_korean_ciNULL보기변경삭제기본인덱스고유값Fulltext
varchar(100)euckr_korean_ciNULL보기변경삭제기본인덱스고유값Fulltext
varchar(100)euckr_korean_ciNULL보기변경삭제기본인덱스고유값Fulltext


memberOther

필드종류Collation보기Null기본값추가실행
int(10)UNSIGNED아니오auto_increment보기변경삭제기본인덱스고유값Fulltext
char(4)euckr_korean_ci아니오보기변경삭제기본인덱스고유값Fulltext
varchar(20)euckr_korean_ciNULL보기변경삭제기본인덱스고유값Fulltext
char(4)euckr_korean_ciNULL보기변경삭제기본인덱스고유값Fulltext
enum('1', '2', '3')euckr_korean_ciNULL보기변경삭제기본인덱스고유값Fulltext
enum('1', '2')euckr_korean_ciNULL보기변경삭제기본인덱스고유값Fulltext
char(3)euckr_korean_ci아니오보기변경삭제기본인덱스고유값Fulltext
enum('1', '2', '3', '4')euckr_korean_ciNULL보기변경삭제기본인덱스고유값Fulltext
enum('1', '2', '3')euckr_korean_ciNULL보기변경삭제기본인덱스고유값Fulltext
enum('1', '2', '3')euckr_korean_ciNULL보기변경삭제기본인덱스고유값Fulltext
enum('A', 'O', 'B', 'AB')euckr_korean_ciNULL보기변경삭제기본인덱스고유값Fulltext
varchar(20)euckr_korean_ciNULL보기변경삭제기본인덱스고유값Fulltext
enum('1', '2', '3')euckr_korean_ciNULL보기변경삭제기본인덱스고유값Fulltext
varchar(20)euckr_korean_ci아니오보기변경삭제기본인덱스고유값Fulltext



memberLevInfo

필드종류Collation보기Null기본값추가실행
int(10)UNSIGNED아니오auto_increment보기변경삭제기본인덱스고유값Fulltext
char(1)euckr_korean_ci아니오보기변경삭제기본인덱스고유값Fulltext
dateNULL보기변경삭제기본인덱스고유값Fulltext
dateNULL보기변경삭제기본인덱스고유값Fulltext
tinyint(3)UNSIGNEDNULL보기변경삭제기본인덱스고유값Fulltext
varchar(20)euckr_korean_ci아니오보기변경삭제기본인덱스고유값Fulltext



membership 핸드폰번호가 null인 데이터의 갯수

select count(*)from membership where tel is null;


birth의 데이터 타입을date로 변환

alter table membership modify birth date;


나이 많은 사람출력,적은 사람 출력

1.select * from membership order by birth asc limit 0,1; 

2.select min(birth) from membership;

3.select min(left(birth,4)) from membership;

4.select * from membership order by birth desc limit 0,1;

나이 많은 사람과 적은사람의 나이차


1.select concat((select birth from membership order by birth desc limit 0,1)-(select birth from membership order by birth asc limit 0,1));

2.select min(left(birth,4))-max(left(birth,4)) as '차' from membership;


주소 업데이트

update membership set addr1="서울시 종로구" where user_id="test1";

update membership set addr1="서울시 강남구" where user_id="test2";

update membership set addr1="부산시 해운대구" where user_id="test3";

update membership set addr1="강원도 속초시" where user_id="test4";

update membership set addr1="경기도 성남시" where user_id="test5";


서울에 살고있는 여성

select *from membership where gender="F" AND addr1 like "%서울%";


아이디 이름 패스워드 모양 출력

select concat(user_id,'  ',user_name,'  ','****') as '아이디/이름/패스워드' from membership; 


job이 j001 j002 j005인 사람 출력

1.selectfrom memberOther where job="j001" or job="j002" or job="j005"; 

2.select * from memberOther where job in('j001','j002','j005');


job이 j001 j002 j005인 사람 출력,취미가h001인 사람

selectfrom memberOther where job="j001" or job="j002" or job="j005" or hobby="h001";


추천인이 없는 사람

select user_id from memberOther where recId is null or trim(recId)="";


혈액형이 O형인 사람의 아이디와 이름을 출력

select user_id,(select user_name from membership where user_id=a.user_id) as '혈액형이 O형인사람' from memberOther a where blood="O";


아이디와 이름 성별 시작일 종료일 출력

select user_id as '아이디',user_name as '이름', gender as '성별',(select levelDayS from memberLevInfo where user_id=a.user_id) as '시작일',(select levelDayE from memberLevInfo where user_id=a.user_id) as '종료일' from membership a;




728x90
반응형

댓글