py)Theano or Conda

If you’re using pyenv, the reason is simple: when pyenv builds Python, it doesn’t allow shared (dynamic) library linkage by default. So you need to rebuild with --enabled-shared:

$ env PYTHON_CONFIGURE_OPTS="--enable-shared" pyenv install 3.6.0

Then, when Theano builds (recall that it’s complaining about recompiling with -fPIC), it is able to link with shared libraries.

 


$ pip freeze > requirements.txt

### install conda
$wget https://repo.anaconda.com/archive/Anaconda3-5.3.1-Linux-x86_64.sh
$bash Anaconda3-5.3.1-Linux-x86_64.sh

$conda install mingw libpython
 

mysql) pr4(Q3)

# 3.
#lang: countrycode, lang, percentage
#country: code, name, population
use world;
select language, round(sum(population*percentage)) as count
from
(
select countrylanguage.CountryCode,
countrylanguage.Percentage, countrylanguage.language,
country.population
from countrylanguage
join country
on countrylanguage.CountryCode=country.code
) as new
group by language
order by count DESC;

# 4.
# name 2개 처리방법/ percentage 사용
#city:population
#country:population
#join country code

select
city.Name,
country.code,
country.name,
round((city.population / country.population)*100, 2) as percentage
from city
join country
on city.countrycode = country.code
where city.population >= 5000000
and round((city.population / country.population)*100, 2) > 10
order by percentage DESC;

# 5.1.
#조건: 면적10000 이상 국가, 인구밀도 200이상
#만약 코드가 다른 셀에 있었다면? join
select
code,
name,
round((population/surfacearea)) as density
from country
where surfacearea >= 10000
order by density DESC;

# 5.2.
select name, count(code) as language_count
from
(select
new.name,
countrylanguage.language,
new.density,
new.code
from
(select
code,
name,
round(population/surfacearea) as density
from country
where surfacearea >= 10000
order by density DESC) as new
join countrylanguage
on countrylanguage.countrycode = new.code
where density >= 200) as new1
group by code
having language_count >= 5
order by language_count DESC;

#6
#조건: 언어 3가지 이하 국가 & 도시인구 300만 이상
#city: population, name
#language: countrycode
use world;

select
new.countrycode,
new1.city_name,
new1.population,
new1.name,
new.language_count,
new.languages
from
(select
countrycode,
count(countrycode) as language_count,
group_concat(language) as languages
from countrylanguage
group by countrycode
having language_count <= 3) as new
join
(select
city.countrycode,
city.name as city_name,
city.population,
country.name as name
from city
join country
on city.countrycode = country.code
where city.population >= 3000000) as new1
on new.countrycode = new1.countrycode
order by population DESC

sql)연습4

— 인덱스 추가
— 같이 사용하는 컬럼은 같이 묶어서 사
create index fdate
on salaries (from_date);

drop index fdate
on salaries;

create index fdate
on salaries (from_date, to_date);

— 조건 from_date은 인덱스 사용, to_date는 사용안함
explain
select *
from salaries
where from_date < “1985-02-01”;

— view
— 가상의 결과테이블
— 실제 테이블이 만들어지지는 않음
— 테이블 조인할 때 사용
— 장점: 쿼리를 줄여서 간단하게 만들 수 있음
— 단점: 한번 생성된 뷰는 수정이 불가능, 인덱스 설정이 불가능
use world;
create view code_name as
select code, name
from country;

select *
from city
join code_name
on city.countrycode = code_name.code

sql) 연습3(join)

use world;
select world;
CREATE TABLE user (
user_id int(11) unsigned NOT NULL AUTO_INCREMENT,
name varchar(30) DEFAULT NULL,
PRIMARY KEY (user_id)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

CREATE TABLE addr (
id int(11) unsigned NOT NULL AUTO_INCREMENT,
addr varchar(30) DEFAULT NULL,
user_id int(11) DEFAULT NULL,
PRIMARY KEY (id)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

INSERT INTO user(name)
VALUES (“jin”),
(“po”),
(“alice”),
(“petter”);

INSERT INTO addr(addr, user_id)
VALUES (“seoul”, 1),
(“pusan”, 2),
(“deajeon”, 3),
(“deagu”, 5),
(“seoul”, 6);

— inner join
select id, user.name, addr.addr
from user
join addr
where user.user_id = addr.user_id;
— on user.user_id=addr.user_id;
— 원리
select *
from user
join addr;

— inner join
select id, user.name, addr.addr
from user
join addr
on user.user_id=addr.user_id;

— 문제 world의 도시이름과 도시의 국가 이름출력
— 국가코드, 도시이름, 국가이름
select *
from city
join country
on city.id=country.id;
— 답
select city.CountryCode, city.name as city_name, country.name as county_name
from city
join country
on city.CountryCode = country.code;

— left join
— 왼쪽 테이블 기준 join; 왼쪽 테이블 데이터는 모두 출력
— 키값이 매핑되는 데이터가 없으면 Null 출력
— 0은 if문으로!
select id, user.name, addr.addr
— user가 left임
from user
left join addr
— addr의 id가 null
on user.user_id = addr.user_id;

— left가 addr
select id, user.name, addr.addr
— user가 left임
from addr
left join user
— user의 id가 null
on user.user_id = addr.user_id;

— right
select id, us거er.name, addr.addr
from addr
right join user
on user.user_id = addr.user_id;

— union
— select 쿼리의 결과를 합쳐서 출력하는 방법
— 자동으로 중복데이터 제
— full outer join 구현
select name
from user
— union all은 중복 제거 안함
union all
select addr
from addr;

— full outer join
select addr.id, user.name, addr.addr
from user
left join addr
on user.user_id = addr.user_id;

select addr.id, user.name, addr.addr
from user
right join addr
on user.user_id = addr.user_id;

— 합친다
select addr.id, user.name, addr.addr
from user
left join addr
on user.user_id = addr.user_id
union
select addr.id, user.name, addr.addr
from user
right join addr
on user.user_id = addr.user_id;

 


— subquery
— query안에 query
use world;

— 1. select절 sub query: world 데이터 베이스에서 전체 나라수 & 도시수 & 언어수 출력
select
(select count(name) from city) as total_city,
— count에 가장 편한 애를 자기가 선택
(select count(*) from country) as total_country,
(select count(distinct(Language)) from countrylanguage) as total_country
— from 없어도 될 때
from dual;

— 2. from절 sub query
— 800만 이상 도시의 국가코드, 국가이름, 도시이름, 도시인구수 출력
— 1)join해서 필터링하는 방법 2)where로 선별 다시 join
— join은 느리니까 적은 데이터로 join 하자
— 틀립 —————————————————-
select *
from
(select countrycode, name, population
from city
— alias 있어야 함
where population > 8000000) as city
join
(select code, name
from country) as country
on country.code = city.countrycode;

— where sub-query
— 800만 이상 도시의 국가코드, 국가이름, 대통령 이름 출력
— 틀림———————————————————————————-
select code, name, HeadOfState
from country
where code in(
— 800 만이상
select countrycode
from city
where Population > 8000000
);

— 문제1 틀림
select
from country;

select name
from country
where
(select population from exico;

— 문제1 답
— 나라 이름과 인구수 필요
select name, population
from country
— where population > 멕시코 인구수보다 큰
where population >(
select population
from country
where name=”Mexico”
)
order by population desc;

— 문제2: city와 country join
— 1)
select country.code, country.name, city.name
from city
join country
on city.CountryCode = country.Code;

select country.name, count(country.name) as count
from city
join country
on city.CountryCode = country.code
group by country.name
order by count desc;