SQL 문법 작성하는법, 파이썬 리스트, 딕셔너리, 조건문, 반복문
SQL 문법은 SELET와 FROM으로 무조건 시작하며 오늘은 WHERE 조건문에 대해서 학습했다.
파이썬은 리스트, 딕셔너리, 조건문, 반복문을 학습하고 연습문제를 풀었다.
1) sparta_employees 테이블에서 모든 직원의 이름(name)과 직급(position)을 선택하는 쿼리를 작성해주세요. = select name, position from sparta_employees
2) sparta_employees 테이블에서 중복 없이 모든 직급(position)을 선택하는 쿼리를 작성해주세요. = select position from sparta_employees
3) sparta_employees 테이블에서 연봉(salary)이 40000과 60000 사이인 직원들을 선택하는 쿼리를 작성해주세요. = select * from sparta_employees
where salary between 40000 and 60000
4) sparta_employees 테이블에서 입사일(hire_date)이 2023년 1월 1일 이전인 모든 직원들을 선택하는 쿼리를 작성해주세요. = select * from sparta_employees
where hire_date < '2023-01-01'
1) 리스트
a = [1,2,3] a.append(5) print(a) #[1,2,3,5]
a.sort(reserve=True) print(a) #[5,3,2,1]
2) 딕셔너리
a ={"one" : 1, "two" : 2} print ("one" in a) # True
print ("Three" in a) # False
people = [{'name' : '우진', 'age':26}, {'name' : '도균', 'age' :25}]
print (people[0]['name']) = '우진'
people = [ {'name': 'bob', 'age': 20, 'score':{'math':90,'science':70}},
{'name': 'carry', 'age': 38, 'score':{'math':40,'science':72}},
{'name': 'smith', 'age': 28, 'score':{'math':80,'science':90}},
{'name': 'john', 'age': 34, 'score':{'math':75,'science':100}}]
smith의 science 점수를 찾는 식
print(people[2]['score']['science']
3) 조건문
money = 4000
if money > 3500:
print("과자를사자")
else:
print("사탕을사자")
= 과자를 사자
age = 15
if age > 20:
print("성인입니다")
elif age <20:
print("청소년입니다")
elif age < 13:
print("무료입니다")
= 청소년입니다
4) 반복문
people = [ {'name': 'bob', 'age': 20},
{'name': 'carry', 'age': 38},
{'name': 'john', 'age': 7},
{'name': 'smith', 'age': 17},
{'name': 'ben', 'age': 27},
{'name': 'bobby', 'age': 57},
{'name': 'red', 'age': 32},
{'name': 'queen', 'age': 25}]
for person in people:
if person ['age'] >20:
print (person ['name'])
= carry, ben, bobby, red, queen
5) 연습문제
짝수를 구하는식
for num in num_list:
if num%2==0:
print(num)
짝수의 수를 구하는식
count = 0
for num in num_list:
if num %2 ==0:
count+=1
print(count)
모든숫자 더하기
result = 0
for num in num_list:
result+=num
print(result)
최대숫자 구하기
max = 0
for num in num_list:
if max < num:
max = num
print (max)
SQL
파이썬