본문 바로가기

SQL

(4)
[mysql] concat, substring, if, case, case + if concat concat은 col과 문자열을 합쳐주는 함수입니다. select concat(name, '의 수학 점수는 ', math, '이고, 영어는 ', eng, '이며 국어는 ', korean, '입니다.') as total from score; date date를 사용해서 간단한 연산을 해보겠습니다. select now() 현재 시각에서 2일과 11시간을 뺍니다. select date_add(now(), interval '-2 11' day_hour) as 'minus day and hour' if 만약 수학 점수가 90이거나 이상이면 훌륭함, 아니면 우수로 출력합니다. select if(math >= 90, '훌륭함', '우수') as 'math score' from score; case if와..
[mysql] Subbranch, group by, having, rollup Subbranch select Name, Population, CountryCode from city where CountryCode = (select CountryCode from city where Name = 'Chicago'); Group by select Name, avg(Population) from country group by Name; Having select max(Population) as max, Min(Population) as min from city having max > 10000000; Rollup select CountryCode, Name, sum(Population) from city group by CountryCode, Name with rollup;
[mysql] join, union There are two sample tables. select * from info; select * from info1; join select * from info join info1 on info.ID = info1.no; the join is to make the same condition both tables based on ID select * from info left join info1 on info.ID = info1.no; The left join is the second table will be into the first table. union select cc.code from info1 as cc union all select dd.code from info as dd; 'unio..
SQL In this post, let me do some basic SQL from free data. mysql> show tables; mysql> select * from city limit 10; mysql> select * from city where CountryCode like '%USA%' limit 10; mysql> select * from city where Population > 6000000 and Population select * from city where CountryCode like '%OR%' limit 10; mysql> select * from city where Population < 500 order by Population desc;