<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
    <channel>
        <title>pirate-turtle.log</title>
        <link>https://velog.io/</link>
        <description></description>
        <lastBuildDate>Wed, 10 Jan 2024 06:16:13 GMT</lastBuildDate>
        <docs>https://validator.w3.org/feed/docs/rss2.html</docs>
        <generator>https://github.com/jpmonette/feed</generator>
        <image>
            <title>pirate-turtle.log</title>
            <url>https://images.velog.io/images/pirate-turtle/profile/d95f0b6e-bb23-413e-b731-ae5f8c8f131e/social.png</url>
            <link>https://velog.io/</link>
        </image>
        <copyright>Copyright (C) 2019. pirate-turtle.log. All rights reserved.</copyright>
        <atom:link href="https://v2.velog.io/rss/pirate-turtle" rel="self" type="application/rss+xml"/>
        <item>
            <title><![CDATA[체크박스 커스텀해보기]]></title>
            <link>https://velog.io/@pirate-turtle/%EC%B2%B4%ED%81%AC%EB%B0%95%EC%8A%A4-%EC%BB%A4%EC%8A%A4%ED%85%80%ED%95%B4%EB%B3%B4%EA%B8%B0</link>
            <guid>https://velog.io/@pirate-turtle/%EC%B2%B4%ED%81%AC%EB%B0%95%EC%8A%A4-%EC%BB%A4%EC%8A%A4%ED%85%80%ED%95%B4%EB%B3%B4%EA%B8%B0</guid>
            <pubDate>Wed, 10 Jan 2024 06:16:13 GMT</pubDate>
            <description><![CDATA[<p>연결된 라벨을 선택하면 체크박스도 함께 선택되는 원리를 이용한 것이다</p>
<ol>
<li>기본 체크박스를 숨긴다</li>
<li>라벨에 박스 콘텐츠를 추가한다</li>
<li>체크된 경우 박스의 스타일을 변경한다</li>
</ol>
<p>체크 이모지를 활용하여 박스에 표시되도록 했다. 그로 인한 문제점은</p>
<ul>
<li>박스 사이즈가 변경되면 font-size 및 line-height 속성을 그에 맞춰 변경해야한다.</li>
<li>환경에 따라 이모지의 모양이 다르게 보일 것이다. 이미지를 사용하면 모든 환경에서 동일한 체크모양이 될 것..
!codepen[pirate-turtle/embed/OJqXGGW?default-tab=css%2Cresult]</li>
</ul>
<p>이미지나 이모지를 사용하지 않고 div를 기울여서 체크모양으로 만드는 방법도 있다.</p>
<ol>
<li>기본 체크박스를 숨긴다</li>
<li>체크박스를 생성한다 위치는 absolute로 지정한다</li>
<li>체크박스 위에 표시될 체크마크를 생성한다 위치는 absolute로 지정한다</li>
<li>체크마크를 평소에는 숨기다가 체크상태가 되면 보여준다</li>
</ol>
<p>!codepen[pirate-turtle/embed/LYaZKNj?default-tab=css%2Cresult]</p>
<p><strong>참고자료</strong></p>
<ul>
<li><a href="https://hongbyul.tistory.com/entry/input-%EC%B2%B4%ED%81%AC%EB%B0%95%EC%8A%A4-CSS-%EB%B3%80%EA%B2%BD%ED%95%98%EA%B8%B0">https://hongbyul.tistory.com/entry/input-%EC%B2%B4%ED%81%AC%EB%B0%95%EC%8A%A4-CSS-%EB%B3%80%EA%B2%BD%ED%95%98%EA%B8%B0</a></li>
<li><a href="https://sophiecial.tistory.com/34">https://sophiecial.tistory.com/34</a></li>
<li><a href="https://www.w3schools.com/howto/howto_css_custom_checkbox.asp">https://www.w3schools.com/howto/howto_css_custom_checkbox.asp</a></li>
</ul>
]]></description>
        </item>
        <item>
            <title><![CDATA[라디오 버튼 색상 바꾸는 법 2가지]]></title>
            <link>https://velog.io/@pirate-turtle/%EB%9D%BC%EB%94%94%EC%98%A4-%EB%B2%84%ED%8A%BC-%EC%83%89%EC%83%81-%EB%B0%94%EA%BE%B8%EB%8A%94-%EB%B2%95-2%EA%B0%80%EC%A7%80</link>
            <guid>https://velog.io/@pirate-turtle/%EB%9D%BC%EB%94%94%EC%98%A4-%EB%B2%84%ED%8A%BC-%EC%83%89%EC%83%81-%EB%B0%94%EA%BE%B8%EB%8A%94-%EB%B2%95-2%EA%B0%80%EC%A7%80</guid>
            <pubDate>Wed, 10 Jan 2024 05:17:16 GMT</pubDate>
            <description><![CDATA[<ol>
<li><p>accent-color를 이용하면 쉽고 빠르게 색을 변경할 수 있다.
!codepen[pirate-turtle/embed/wvOWOeZ?default-tab=css%2Cresult]
하지만 원하는 컬러가 원하지 않는 배경색과 매칭될수도 있고, 테두리와 안쪽 원의 색상을 다르게 주고 싶을수도 있다. </p>
</li>
<li><p>직접 커스텀한다.
!codepen[pirate-turtle/embed/ExMyJXp?default-tab=css%2Cresult]</p>
</li>
</ol>
<p><strong>참고자료</strong></p>
<ul>
<li><a href="https://www.daleseo.com/css-accent-color/">https://www.daleseo.com/css-accent-color/</a></li>
<li><a href="https://www.inflearn.com/questions/903602/radio-%EB%B2%84%ED%8A%BC-css-%EB%A1%9C-%EC%83%89%EC%83%81-%EB%B3%80%EA%B2%BD%ED%95%98%EB%8A%94-%EB%B0%A9%EB%B2%95">https://www.inflearn.com/questions/903602/radio-%EB%B2%84%ED%8A%BC-css-%EB%A1%9C-%EC%83%89%EC%83%81-%EB%B3%80%EA%B2%BD%ED%95%98%EB%8A%94-%EB%B0%A9%EB%B2%95</a></li>
<li><a href="https://velog.io/@ohjoo1130/CSS-radio-%EB%B2%84%ED%8A%BC-%EC%83%89%EC%83%81-%EB%B0%94%EA%BE%B8%EA%B8%B0">https://velog.io/@ohjoo1130/CSS-radio-%EB%B2%84%ED%8A%BC-%EC%83%89%EC%83%81-%EB%B0%94%EA%BE%B8%EA%B8%B0</a></li>
</ul>
]]></description>
        </item>
        <item>
            <title><![CDATA[box-sizing]]></title>
            <link>https://velog.io/@pirate-turtle/box-sizing</link>
            <guid>https://velog.io/@pirate-turtle/box-sizing</guid>
            <pubDate>Mon, 18 Dec 2023 05:56:19 GMT</pubDate>
            <description><![CDATA[<p>이전 포스트에서 width나 height 속성은 요소의 크기 (content 크기) 를 지정하는 것이고,
최종 사이즈는 border, padding, 요소의 크기를 더해서 잘 계산해야겠다고 적었다. 그러나 border까지를 전체 크기로 지정할 수 있는 속성이 있었다. 바로 <code>box-sizing</code>이라는 속성이다.</p>
<ul>
<li><code>box-sizing: content-box</code> → 기본값. width, height는 content 영역 크기를 의미하고 주변에 padding과 border가 추가로 둘러진다</li>
<li><code>box-sizing: border-box</code>로 두면 width, height는 총 너비, 총 높이를 의미하게 된다. border, padding, content 모두가 포함되는 사이즈인 것.</li>
</ul>
<p>글로 쓰니까 알아보기 어렵지만 실제로 이미지를 보면 직관적이다
!codepen[pirate-turtle/embed/dyaxRjm?default-tab=html%2Cresult]</p>
<p>아래처럼 div 태그 셀렉터에 써두면 편하다고 한다.</p>
<pre><code class="language-CSS">div {
    box-sizing: border-box;
}</code></pre>
<p>앞으로 더 편리하게 요소의 크기를 지정할 수 있을 것 같다.</p>
<h3 id="참고">참고</h3>
<ul>
<li><a href="https://developer.mozilla.org/ko/docs/Web/CSS/box-sizing">https://developer.mozilla.org/ko/docs/Web/CSS/box-sizing</a></li>
<li>코딩애플 HTML/CSS 강의</li>
</ul>
]]></description>
        </item>
        <item>
            <title><![CDATA[margin과 padding]]></title>
            <link>https://velog.io/@pirate-turtle/margin%EA%B3%BC-padding</link>
            <guid>https://velog.io/@pirate-turtle/margin%EA%B3%BC-padding</guid>
            <pubDate>Sat, 16 Dec 2023 03:34:01 GMT</pubDate>
            <description><![CDATA[<p>네비게이션 바를 만들어보려고 했는데 자식 요소가 자꾸 부모 영역을 초과했다. margin과 padding에 대한 이해가 부족해서였다. 나는 width와 height가 margin과 padding을 포함하는 전체 사이즈를 지정해주는 줄 알았다😂</p>
<p>답은 개발자도구에서 많이 보던 이 사진에 있었다.
<img src="https://velog.velcdn.com/images/pirate-turtle/post/375d7673-f68b-4bbc-8cbd-257657b852be/image.png" alt=""></p>
<p>width와 height는 요소의 size를 지정해주고 (맨 안쪽 파란네모) padding과 margin은 그 바깥에서 처리된다. border를 기준으로 안쪽의 여백이 padding, 바깥쪽의 여백이 margin이었던것...</p>
<p>그리고 부모의 width나 height가 고정되어있을 때, 자식의 크기가 부모보다 크면 영역을 초과한다. <code>overflow</code>속성이 기본적으로 visible이어서 넘친 콘텐츠를 그대로 보여주는 것. <code>overflow</code> 속성을 이용해서  숨기거나 자르거나 스크롤이 가능하게 할 수 있다고 한다.
<a href="https://developer.mozilla.org/ko/docs/Web/CSS/overflow">https://developer.mozilla.org/ko/docs/Web/CSS/overflow</a></p>
<p>영역이 초과되는 현상을 원하지 않는다면 요소, border, margin, padding을 모두 합쳤을때의 크기를 잘 고려해야할 것 같다.</p>
<p>!codepen[pirate-turtle/embed/oNmravg?default-tab=html%2Cresult]</p>
<h4 id="참고">참고</h4>
<ul>
<li><a href="https://tcpschool.com/css/css_boxmodel_boxmodel">https://tcpschool.com/css/css_boxmodel_boxmodel</a></li>
<li><a href="https://velog.io/@hyejin4169/CSS-margin-padding-%EC%B0%A8%EC%9D%B4%EC%A0%90%EA%B3%BC-%EC%82%AC%EC%9A%A9%EB%B2%95-%EC%A0%95%EB%A6%AC">https://velog.io/@hyejin4169/CSS-margin-padding-%EC%B0%A8%EC%9D%B4%EC%A0%90%EA%B3%BC-%EC%82%AC%EC%9A%A9%EB%B2%95-%EC%A0%95%EB%A6%AC</a></li>
</ul>
]]></description>
        </item>
        <item>
            <title><![CDATA[float]]></title>
            <link>https://velog.io/@pirate-turtle/float</link>
            <guid>https://velog.io/@pirate-turtle/float</guid>
            <pubDate>Fri, 15 Dec 2023 06:20:29 GMT</pubDate>
            <description><![CDATA[<p>코딩애플에서 display:block과 float속성에 대해 배웠다.
레퍼런스를 더 찾아보고 스스로 실험해본 내용을 정리하겠다.</p>
<h4 id="display-block">display: block</h4>
<ul>
<li>항상 새로운 라인에서 시작한다</li>
<li>화면 크기 전체의 가로폭을 차지한다 (width: 100%. width를 지정해도 오른쪽에 요소가 들어가지 않는다) </li>
<li>이미 block 속성을 암시적으로 지닌 태그들이 있다 (div, p, li 등등)</li>
</ul>
<h4 id="float">float</h4>
<ul>
<li>float 속성이 지정된 요소는 다음 요소 위에 떠있게 된다 (레이어가 다른 느낌. 그래도 텍스트와 이미지는 float 요소를 피해서 보인다)</li>
<li>부모 요소의 높이가 float 요소까지 확장되지 않는다. 이 경우 부모 요소에 <code>overflow: hidden</code> 속성을 주면 해결할 수 있다.</li>
<li><code>float:left</code> 속성을 주면 float 요소끼리 왼쪽 정렬이 되고, <code>float: right</code>는 오른쪽 정렬이 된다</li>
<li>float 다음에 오는 요소가 float 요소와 겹쳐지는 것을 원하지 않는다면, 해당 요소에 <code>clear</code> 속성을 주면 된다<ul>
<li>clear:left - float:left 속성에 영향을 받지 않게 된다</li>
<li>clear:right - float:right 속성에 영향을 받지 않게 된다</li>
<li>clear:both - float:left, float:right 두 속성에 모두 영향을 받지 않게 된다</li>
</ul>
</li>
<li>float 속성이 relative한 위치 지정을 하기 때문에 <code>position: absolute</code> 속성이 적용되지 않는다고 한다.</li>
</ul>
<p>!codepen[pirate-turtle/embed/xxMoRdw?default-tab=html%2Cresult]</p>
<h4 id="참고자료">참고자료</h4>
<ul>
<li>코딩애플 - 레이아웃만들기 1: 호환성 좋은 float</li>
<li><a href="https://poiemaweb.com/css3-display">https://poiemaweb.com/css3-display</a></li>
<li><a href="https://developer.mozilla.org/ko/docs/Web/CSS/float">https://developer.mozilla.org/ko/docs/Web/CSS/float</a></li>
<li><a href="https://inpa.tistory.com/entry/CSS-%F0%9F%93%9A-float">https://inpa.tistory.com/entry/CSS-%F0%9F%93%9A-float</a></li>
<li><a href="https://developer.mozilla.org/ko/docs/Web/CSS/clear">https://developer.mozilla.org/ko/docs/Web/CSS/clear</a></li>
<li><a href="https://velog.io/@nalsae/%EB%82%B4%EB%B3%B4%EC%A0%95CSS-float-%EB%94%A5-%EB%8B%A4%EC%9D%B4%EB%B8%8C">https://velog.io/@nalsae/%EB%82%B4%EB%B3%B4%EC%A0%95CSS-float-%EB%94%A5-%EB%8B%A4%EC%9D%B4%EB%B8%8C</a></li>
</ul>
]]></description>
        </item>
        <item>
            <title><![CDATA[[SQL] 데이터 조회]]></title>
            <link>https://velog.io/@pirate-turtle/%EB%8D%B0%EC%9D%B4%ED%84%B0-%EC%A1%B0%ED%9A%8C</link>
            <guid>https://velog.io/@pirate-turtle/%EB%8D%B0%EC%9D%B4%ED%84%B0-%EC%A1%B0%ED%9A%8C</guid>
            <pubDate>Wed, 20 Jul 2022 08:21:15 GMT</pubDate>
            <description><![CDATA[<blockquote>
<p>주피터 노트북 파일을 마크다운으로 변환하여 작성한 글입니다.
코드는 깃헙에 정리해두었습니다!
<a href="https://github.com/pirate-turtle/SQL">https://github.com/pirate-turtle/SQL</a></p>
</blockquote>
<h1 id="데이터-조회">데이터 조회</h1>
<p>데이터 조회 시 유용한 문법에 대해 알아봅니다.</p>
<ul>
<li><a href="#select">SELECT</a><ul>
<li><a href="#limit">LIMIT</a></li>
<li><a href="#%EC%97%B0%EA%B2%B0-%EC%97%B0%EC%82%B0%EC%9E%90">연결 연산자 (||)</a></li>
<li><a href="#as">AS</a></li>
</ul>
</li>
<li><a href="#distinct">DISTINCT</a></li>
<li><a href="#order-by">ORDER BY</a></li>
<li><a href="#where">WHERE</a><ul>
<li><a href="#between">BETWEEN</a></li>
<li><a href="#in">IN</a></li>
<li><a href="#like">LIKE</a></li>
</ul>
</li>
</ul>
<blockquote>
<p><br/>사용한 데이터 정보<br><br/>
<img src="https://www.sqlitetutorial.net/wp-content/uploads/2015/11/sqlite-sample-database-color.jpg" alt="IMAGE"><br><a href="https://www.sqlitetutorial.net/sqlite-sample-database/">https://www.sqlitetutorial.net/sqlite-sample-database/</a><br><br/></p>
</blockquote>
<h2 id="시작하기-전-실행하기">시작하기 전 실행하기!</h2>
<pre><code class="language-python">import sqlite3
from prettytable import from_db_cursor

# SQLite 데이터베이스에 연결하기 위해 connect 생성
con = sqlite3.connect(&#39;./database/chinook.db&#39;)
con.row_factory = sqlite3.Row

# cursor 생성
cur = con.cursor()</code></pre>
<h2 id="select">SELECT</h2>
<p>원하는 데이터를 조회할 때 사용합니다.</p>
<p>※ SQL은 대소문자를 구분하지 않습니다. 명령문을 대문자, 그 외는 소문자로 입력하면 가독성이 좋아집니다.</p>
<pre><code class="language-python"># 한번에 모든 컬럼 조회
# SELECT * FROM table_name;
cur.execute(&quot;&quot;&quot;
    SELECT *
    FROM customers
    &quot;&quot;&quot;)

# 데이터 양이 많으니 상위 10개만 일단 보기
from_db_cursor(cur)[:10]</code></pre>
<table>
    <thead>
        <tr>
            <th>CustomerId</th>
            <th>FirstName</th>
            <th>LastName</th>
            <th>Company</th>
            <th>Address</th>
            <th>City</th>
            <th>State</th>
            <th>Country</th>
            <th>PostalCode</th>
            <th>Phone</th>
            <th>Fax</th>
            <th>Email</th>
            <th>SupportRepId</th>
        </tr>
    </thead>
    <tbody>
        <tr>
            <td>1</td>
            <td>Luís</td>
            <td>Gonçalves</td>
            <td>Embraer - Empresa Brasileira de Aeronáutica S.A.</td>
            <td>Av. Brigadeiro Faria Lima, 2170</td>
            <td>São José dos Campos</td>
            <td>SP</td>
            <td>Brazil</td>
            <td>12227-000</td>
            <td>+55 (12) 3923-5555</td>
            <td>+55 (12) 3923-5566</td>
            <td>luisg@embraer.com.br</td>
            <td>3</td>
        </tr>
        <tr>
            <td>2</td>
            <td>Leonie</td>
            <td>Köhler</td>
            <td>None</td>
            <td>Theodor-Heuss-Straße 34</td>
            <td>Stuttgart</td>
            <td>None</td>
            <td>Germany</td>
            <td>70174</td>
            <td>+49 0711 2842222</td>
            <td>None</td>
            <td>leonekohler@surfeu.de</td>
            <td>5</td>
        </tr>
        <tr>
            <td>3</td>
            <td>François</td>
            <td>Tremblay</td>
            <td>None</td>
            <td>1498 rue Bélanger</td>
            <td>Montréal</td>
            <td>QC</td>
            <td>Canada</td>
            <td>H2G 1A7</td>
            <td>+1 (514) 721-4711</td>
            <td>None</td>
            <td>ftremblay@gmail.com</td>
            <td>3</td>
        </tr>
        <tr>
            <td>4</td>
            <td>Bjørn</td>
            <td>Hansen</td>
            <td>None</td>
            <td>Ullevålsveien 14</td>
            <td>Oslo</td>
            <td>None</td>
            <td>Norway</td>
            <td>0171</td>
            <td>+47 22 44 22 22</td>
            <td>None</td>
            <td>bjorn.hansen@yahoo.no</td>
            <td>4</td>
        </tr>
        <tr>
            <td>5</td>
            <td>František</td>
            <td>Wichterlová</td>
            <td>JetBrains s.r.o.</td>
            <td>Klanova 9/506</td>
            <td>Prague</td>
            <td>None</td>
            <td>Czech Republic</td>
            <td>14700</td>
            <td>+420 2 4172 5555</td>
            <td>+420 2 4172 5555</td>
            <td>frantisekw@jetbrains.com</td>
            <td>4</td>
        </tr>
        <tr>
            <td>6</td>
            <td>Helena</td>
            <td>Holý</td>
            <td>None</td>
            <td>Rilská 3174/6</td>
            <td>Prague</td>
            <td>None</td>
            <td>Czech Republic</td>
            <td>14300</td>
            <td>+420 2 4177 0449</td>
            <td>None</td>
            <td>hholy@gmail.com</td>
            <td>5</td>
        </tr>
        <tr>
            <td>7</td>
            <td>Astrid</td>
            <td>Gruber</td>
            <td>None</td>
            <td>Rotenturmstraße 4, 1010 Innere Stadt</td>
            <td>Vienne</td>
            <td>None</td>
            <td>Austria</td>
            <td>1010</td>
            <td>+43 01 5134505</td>
            <td>None</td>
            <td>astrid.gruber@apple.at</td>
            <td>5</td>
        </tr>
        <tr>
            <td>8</td>
            <td>Daan</td>
            <td>Peeters</td>
            <td>None</td>
            <td>Grétrystraat 63</td>
            <td>Brussels</td>
            <td>None</td>
            <td>Belgium</td>
            <td>1000</td>
            <td>+32 02 219 03 03</td>
            <td>None</td>
            <td>daan_peeters@apple.be</td>
            <td>4</td>
        </tr>
        <tr>
            <td>9</td>
            <td>Kara</td>
            <td>Nielsen</td>
            <td>None</td>
            <td>Sønder Boulevard 51</td>
            <td>Copenhagen</td>
            <td>None</td>
            <td>Denmark</td>
            <td>1720</td>
            <td>+453 3331 9991</td>
            <td>None</td>
            <td>kara.nielsen@jubii.dk</td>
            <td>4</td>
        </tr>
        <tr>
            <td>10</td>
            <td>Eduardo</td>
            <td>Martins</td>
            <td>Woodstock Discos</td>
            <td>Rua Dr. Falcão Filho, 155</td>
            <td>São Paulo</td>
            <td>SP</td>
            <td>Brazil</td>
            <td>01007-010</td>
            <td>+55 (11) 3033-5446</td>
            <td>+55 (11) 3033-4564</td>
            <td>eduardo@woodstock.com.br</td>
            <td>4</td>
        </tr>
    </tbody>
</table>




<pre><code class="language-python"># 원하는 컬럼만 지정해서 조회 가능
# SELECT column1, column2 FROM table_name;
cur.execute(&quot;&quot;&quot;
    SELECT customerid, firstname, city, state
    FROM customers
    &quot;&quot;&quot;)

from_db_cursor(cur)[:10]</code></pre>
<table>
    <thead>
        <tr>
            <th>CustomerId</th>
            <th>FirstName</th>
            <th>City</th>
            <th>State</th>
        </tr>
    </thead>
    <tbody>
        <tr>
            <td>1</td>
            <td>Luís</td>
            <td>São José dos Campos</td>
            <td>SP</td>
        </tr>
        <tr>
            <td>2</td>
            <td>Leonie</td>
            <td>Stuttgart</td>
            <td>None</td>
        </tr>
        <tr>
            <td>3</td>
            <td>François</td>
            <td>Montréal</td>
            <td>QC</td>
        </tr>
        <tr>
            <td>4</td>
            <td>Bjørn</td>
            <td>Oslo</td>
            <td>None</td>
        </tr>
        <tr>
            <td>5</td>
            <td>František</td>
            <td>Prague</td>
            <td>None</td>
        </tr>
        <tr>
            <td>6</td>
            <td>Helena</td>
            <td>Prague</td>
            <td>None</td>
        </tr>
        <tr>
            <td>7</td>
            <td>Astrid</td>
            <td>Vienne</td>
            <td>None</td>
        </tr>
        <tr>
            <td>8</td>
            <td>Daan</td>
            <td>Brussels</td>
            <td>None</td>
        </tr>
        <tr>
            <td>9</td>
            <td>Kara</td>
            <td>Copenhagen</td>
            <td>None</td>
        </tr>
        <tr>
            <td>10</td>
            <td>Eduardo</td>
            <td>São Paulo</td>
            <td>SP</td>
        </tr>
    </tbody>
</table>




<pre><code class="language-python"># 간단한 연산 결과를 얻을 수도 있다
cur.execute(&quot;SELECT 1+1&quot;)

from_db_cursor(cur)</code></pre>
<table>
    <thead>
        <tr>
            <th>1+1</th>
        </tr>
    </thead>
    <tbody>
        <tr>
            <td>2</td>
        </tr>
    </tbody>
</table>




<pre><code class="language-python"># 여러개도 가능하다!
cur.execute(&quot;SELECT 1+1, 2*5&quot;)

from_db_cursor(cur)</code></pre>
<table>
    <thead>
        <tr>
            <th>1+1</th>
            <th>2*5</th>
        </tr>
    </thead>
    <tbody>
        <tr>
            <td>2</td>
            <td>10</td>
        </tr>
    </tbody>
</table>




<pre><code class="language-python"># 컬럼끼리 연산하는것도 가능함
cur.execute(&quot;&quot;&quot;
    SELECT customerid + supportrepid, firstname, city, state
    FROM customers
    &quot;&quot;&quot;)

from_db_cursor(cur)[:10]</code></pre>
<table>
    <thead>
        <tr>
            <th>customerid + supportrepid</th>
            <th>FirstName</th>
            <th>City</th>
            <th>State</th>
        </tr>
    </thead>
    <tbody>
        <tr>
            <td>4</td>
            <td>Luís</td>
            <td>São José dos Campos</td>
            <td>SP</td>
        </tr>
        <tr>
            <td>7</td>
            <td>Leonie</td>
            <td>Stuttgart</td>
            <td>None</td>
        </tr>
        <tr>
            <td>6</td>
            <td>François</td>
            <td>Montréal</td>
            <td>QC</td>
        </tr>
        <tr>
            <td>8</td>
            <td>Bjørn</td>
            <td>Oslo</td>
            <td>None</td>
        </tr>
        <tr>
            <td>9</td>
            <td>František</td>
            <td>Prague</td>
            <td>None</td>
        </tr>
        <tr>
            <td>11</td>
            <td>Helena</td>
            <td>Prague</td>
            <td>None</td>
        </tr>
        <tr>
            <td>12</td>
            <td>Astrid</td>
            <td>Vienne</td>
            <td>None</td>
        </tr>
        <tr>
            <td>12</td>
            <td>Daan</td>
            <td>Brussels</td>
            <td>None</td>
        </tr>
        <tr>
            <td>13</td>
            <td>Kara</td>
            <td>Copenhagen</td>
            <td>None</td>
        </tr>
        <tr>
            <td>14</td>
            <td>Eduardo</td>
            <td>São Paulo</td>
            <td>SP</td>
        </tr>
    </tbody>
</table>



<h3 id="limit">LIMIT</h3>
<p>쿼리 결과를 원하는 행 수 만큼만 받도록 합니다.</p>
<pre><code class="language-python">cur.execute(&quot;&quot;&quot;
    SELECT *
    FROM customers
    LIMIT 5
    &quot;&quot;&quot;)

from_db_cursor(cur)</code></pre>
<table>
    <thead>
        <tr>
            <th>CustomerId</th>
            <th>FirstName</th>
            <th>LastName</th>
            <th>Company</th>
            <th>Address</th>
            <th>City</th>
            <th>State</th>
            <th>Country</th>
            <th>PostalCode</th>
            <th>Phone</th>
            <th>Fax</th>
            <th>Email</th>
            <th>SupportRepId</th>
        </tr>
    </thead>
    <tbody>
        <tr>
            <td>1</td>
            <td>Luís</td>
            <td>Gonçalves</td>
            <td>Embraer - Empresa Brasileira de Aeronáutica S.A.</td>
            <td>Av. Brigadeiro Faria Lima, 2170</td>
            <td>São José dos Campos</td>
            <td>SP</td>
            <td>Brazil</td>
            <td>12227-000</td>
            <td>+55 (12) 3923-5555</td>
            <td>+55 (12) 3923-5566</td>
            <td>luisg@embraer.com.br</td>
            <td>3</td>
        </tr>
        <tr>
            <td>2</td>
            <td>Leonie</td>
            <td>Köhler</td>
            <td>None</td>
            <td>Theodor-Heuss-Straße 34</td>
            <td>Stuttgart</td>
            <td>None</td>
            <td>Germany</td>
            <td>70174</td>
            <td>+49 0711 2842222</td>
            <td>None</td>
            <td>leonekohler@surfeu.de</td>
            <td>5</td>
        </tr>
        <tr>
            <td>3</td>
            <td>François</td>
            <td>Tremblay</td>
            <td>None</td>
            <td>1498 rue Bélanger</td>
            <td>Montréal</td>
            <td>QC</td>
            <td>Canada</td>
            <td>H2G 1A7</td>
            <td>+1 (514) 721-4711</td>
            <td>None</td>
            <td>ftremblay@gmail.com</td>
            <td>3</td>
        </tr>
        <tr>
            <td>4</td>
            <td>Bjørn</td>
            <td>Hansen</td>
            <td>None</td>
            <td>Ullevålsveien 14</td>
            <td>Oslo</td>
            <td>None</td>
            <td>Norway</td>
            <td>0171</td>
            <td>+47 22 44 22 22</td>
            <td>None</td>
            <td>bjorn.hansen@yahoo.no</td>
            <td>4</td>
        </tr>
        <tr>
            <td>5</td>
            <td>František</td>
            <td>Wichterlová</td>
            <td>JetBrains s.r.o.</td>
            <td>Klanova 9/506</td>
            <td>Prague</td>
            <td>None</td>
            <td>Czech Republic</td>
            <td>14700</td>
            <td>+420 2 4172 5555</td>
            <td>+420 2 4172 5555</td>
            <td>frantisekw@jetbrains.com</td>
            <td>4</td>
        </tr>
    </tbody>
</table>



<p>OFFSET 키워드로 행을 얼마만큼 건너뛸것인지 지정할 수 있습니다.</p>
<pre><code class="language-python"># offset을 n으로 지정하면 n행 건너뛰고 n+1행부터 리턴
cur.execute(&quot;&quot;&quot;
    SELECT *
    FROM customers
    LIMIT 5 OFFSET 10
    &quot;&quot;&quot;)

from_db_cursor(cur)</code></pre>
<table>
    <thead>
        <tr>
            <th>CustomerId</th>
            <th>FirstName</th>
            <th>LastName</th>
            <th>Company</th>
            <th>Address</th>
            <th>City</th>
            <th>State</th>
            <th>Country</th>
            <th>PostalCode</th>
            <th>Phone</th>
            <th>Fax</th>
            <th>Email</th>
            <th>SupportRepId</th>
        </tr>
    </thead>
    <tbody>
        <tr>
            <td>11</td>
            <td>Alexandre</td>
            <td>Rocha</td>
            <td>Banco do Brasil S.A.</td>
            <td>Av. Paulista, 2022</td>
            <td>São Paulo</td>
            <td>SP</td>
            <td>Brazil</td>
            <td>01310-200</td>
            <td>+55 (11) 3055-3278</td>
            <td>+55 (11) 3055-8131</td>
            <td>alero@uol.com.br</td>
            <td>5</td>
        </tr>
        <tr>
            <td>12</td>
            <td>Roberto</td>
            <td>Almeida</td>
            <td>Riotur</td>
            <td>Praça Pio X, 119</td>
            <td>Rio de Janeiro</td>
            <td>RJ</td>
            <td>Brazil</td>
            <td>20040-020</td>
            <td>+55 (21) 2271-7000</td>
            <td>+55 (21) 2271-7070</td>
            <td>roberto.almeida@riotur.gov.br</td>
            <td>3</td>
        </tr>
        <tr>
            <td>13</td>
            <td>Fernanda</td>
            <td>Ramos</td>
            <td>None</td>
            <td>Qe 7 Bloco G</td>
            <td>Brasília</td>
            <td>DF</td>
            <td>Brazil</td>
            <td>71020-677</td>
            <td>+55 (61) 3363-5547</td>
            <td>+55 (61) 3363-7855</td>
            <td>fernadaramos4@uol.com.br</td>
            <td>4</td>
        </tr>
        <tr>
            <td>14</td>
            <td>Mark</td>
            <td>Philips</td>
            <td>Telus</td>
            <td>8210 111 ST NW</td>
            <td>Edmonton</td>
            <td>AB</td>
            <td>Canada</td>
            <td>T6G 2C7</td>
            <td>+1 (780) 434-4554</td>
            <td>+1 (780) 434-5565</td>
            <td>mphilips12@shaw.ca</td>
            <td>5</td>
        </tr>
        <tr>
            <td>15</td>
            <td>Jennifer</td>
            <td>Peterson</td>
            <td>Rogers Canada</td>
            <td>700 W Pender Street</td>
            <td>Vancouver</td>
            <td>BC</td>
            <td>Canada</td>
            <td>V6C 1G8</td>
            <td>+1 (604) 688-2255</td>
            <td>+1 (604) 688-8756</td>
            <td>jenniferp@rogers.ca</td>
            <td>3</td>
        </tr>
    </tbody>
</table>



<p>OFFSET 키워드를 사용하지 않고 지정할 수도 있습니다.</p>
<pre><code class="language-python"># 앞에 오는 숫자가 offset, 뒤에 오는 숫자가 limit
cur.execute(&quot;&quot;&quot;
    SELECT *
    FROM customers
    LIMIT 10, 5
    &quot;&quot;&quot;)

from_db_cursor(cur)</code></pre>
<table>
    <thead>
        <tr>
            <th>CustomerId</th>
            <th>FirstName</th>
            <th>LastName</th>
            <th>Company</th>
            <th>Address</th>
            <th>City</th>
            <th>State</th>
            <th>Country</th>
            <th>PostalCode</th>
            <th>Phone</th>
            <th>Fax</th>
            <th>Email</th>
            <th>SupportRepId</th>
        </tr>
    </thead>
    <tbody>
        <tr>
            <td>11</td>
            <td>Alexandre</td>
            <td>Rocha</td>
            <td>Banco do Brasil S.A.</td>
            <td>Av. Paulista, 2022</td>
            <td>São Paulo</td>
            <td>SP</td>
            <td>Brazil</td>
            <td>01310-200</td>
            <td>+55 (11) 3055-3278</td>
            <td>+55 (11) 3055-8131</td>
            <td>alero@uol.com.br</td>
            <td>5</td>
        </tr>
        <tr>
            <td>12</td>
            <td>Roberto</td>
            <td>Almeida</td>
            <td>Riotur</td>
            <td>Praça Pio X, 119</td>
            <td>Rio de Janeiro</td>
            <td>RJ</td>
            <td>Brazil</td>
            <td>20040-020</td>
            <td>+55 (21) 2271-7000</td>
            <td>+55 (21) 2271-7070</td>
            <td>roberto.almeida@riotur.gov.br</td>
            <td>3</td>
        </tr>
        <tr>
            <td>13</td>
            <td>Fernanda</td>
            <td>Ramos</td>
            <td>None</td>
            <td>Qe 7 Bloco G</td>
            <td>Brasília</td>
            <td>DF</td>
            <td>Brazil</td>
            <td>71020-677</td>
            <td>+55 (61) 3363-5547</td>
            <td>+55 (61) 3363-7855</td>
            <td>fernadaramos4@uol.com.br</td>
            <td>4</td>
        </tr>
        <tr>
            <td>14</td>
            <td>Mark</td>
            <td>Philips</td>
            <td>Telus</td>
            <td>8210 111 ST NW</td>
            <td>Edmonton</td>
            <td>AB</td>
            <td>Canada</td>
            <td>T6G 2C7</td>
            <td>+1 (780) 434-4554</td>
            <td>+1 (780) 434-5565</td>
            <td>mphilips12@shaw.ca</td>
            <td>5</td>
        </tr>
        <tr>
            <td>15</td>
            <td>Jennifer</td>
            <td>Peterson</td>
            <td>Rogers Canada</td>
            <td>700 W Pender Street</td>
            <td>Vancouver</td>
            <td>BC</td>
            <td>Canada</td>
            <td>V6C 1G8</td>
            <td>+1 (604) 688-2255</td>
            <td>+1 (604) 688-8756</td>
            <td>jenniferp@rogers.ca</td>
            <td>3</td>
        </tr>
    </tbody>
</table>



<h3 id="연결-연산자-">연결 연산자 (||)</h3>
<p>여러 컬럼의 값 또는 문자열을 합쳐 하나의 컬럼으로 출력합니다.<br>문자열은 작은 따옴표(&#39;)로 감싸서 입력해야 합니다.</p>
<pre><code class="language-python">cur.execute(&quot;&quot;&quot;
    SELECT firstname||&#39; &#39;||lastname
    FROM customers
    LIMIT 10
    &quot;&quot;&quot;)

from_db_cursor(cur)</code></pre>
<table>
    <thead>
        <tr>
            <th>firstname||&#x27; &#x27;||lastname</th>
        </tr>
    </thead>
    <tbody>
        <tr>
            <td>Luís Gonçalves</td>
        </tr>
        <tr>
            <td>Leonie Köhler</td>
        </tr>
        <tr>
            <td>François Tremblay</td>
        </tr>
        <tr>
            <td>Bjørn Hansen</td>
        </tr>
        <tr>
            <td>František Wichterlová</td>
        </tr>
        <tr>
            <td>Helena Holý</td>
        </tr>
        <tr>
            <td>Astrid Gruber</td>
        </tr>
        <tr>
            <td>Daan Peeters</td>
        </tr>
        <tr>
            <td>Kara Nielsen</td>
        </tr>
        <tr>
            <td>Eduardo Martins</td>
        </tr>
    </tbody>
</table>




<pre><code class="language-python">cur.execute(&quot;&quot;&quot;
    SELECT customerid, &#39;My name is &#39;||firstname||&#39; &#39;||lastname
    FROM customers
    LIMIT 10
    &quot;&quot;&quot;)

from_db_cursor(cur)</code></pre>
<table>
    <thead>
        <tr>
            <th>CustomerId</th>
            <th>&#x27;My name is &#x27;||firstname||&#x27; &#x27;||lastname</th>
        </tr>
    </thead>
    <tbody>
        <tr>
            <td>1</td>
            <td>My name is Luís Gonçalves</td>
        </tr>
        <tr>
            <td>2</td>
            <td>My name is Leonie Köhler</td>
        </tr>
        <tr>
            <td>3</td>
            <td>My name is François Tremblay</td>
        </tr>
        <tr>
            <td>4</td>
            <td>My name is Bjørn Hansen</td>
        </tr>
        <tr>
            <td>5</td>
            <td>My name is František Wichterlová</td>
        </tr>
        <tr>
            <td>6</td>
            <td>My name is Helena Holý</td>
        </tr>
        <tr>
            <td>7</td>
            <td>My name is Astrid Gruber</td>
        </tr>
        <tr>
            <td>8</td>
            <td>My name is Daan Peeters</td>
        </tr>
        <tr>
            <td>9</td>
            <td>My name is Kara Nielsen</td>
        </tr>
        <tr>
            <td>10</td>
            <td>My name is Eduardo Martins</td>
        </tr>
    </tbody>
</table>



<h3 id="as">AS</h3>
<p>컬럼 및 테이블에 임시로 별명을 지어줄 수 있습니다.  </p>
<pre><code class="language-python"># SELECT column1 AS nickname FROM tablename
cur.execute(&quot;&quot;&quot;
    SELECT customerid, firstname||&#39; &#39;||lastname AS Name
    FROM customers
    LIMIT 10
    &quot;&quot;&quot;)

from_db_cursor(cur)</code></pre>
<table>
    <thead>
        <tr>
            <th>CustomerId</th>
            <th>Name</th>
        </tr>
    </thead>
    <tbody>
        <tr>
            <td>1</td>
            <td>Luís Gonçalves</td>
        </tr>
        <tr>
            <td>2</td>
            <td>Leonie Köhler</td>
        </tr>
        <tr>
            <td>3</td>
            <td>François Tremblay</td>
        </tr>
        <tr>
            <td>4</td>
            <td>Bjørn Hansen</td>
        </tr>
        <tr>
            <td>5</td>
            <td>František Wichterlová</td>
        </tr>
        <tr>
            <td>6</td>
            <td>Helena Holý</td>
        </tr>
        <tr>
            <td>7</td>
            <td>Astrid Gruber</td>
        </tr>
        <tr>
            <td>8</td>
            <td>Daan Peeters</td>
        </tr>
        <tr>
            <td>9</td>
            <td>Kara Nielsen</td>
        </tr>
        <tr>
            <td>10</td>
            <td>Eduardo Martins</td>
        </tr>
    </tbody>
</table>




<pre><code class="language-python"># 별명에 공백, 특수문자 등을 포함하고 싶은 경우 작은따옴표로 감싸서 문자열 형태로 만들어야 함
cur.execute(&quot;&quot;&quot;
    SELECT customerid, firstname||&#39; &#39;||lastname AS &#39;My Name☆&#39;
    FROM customers
    LIMIT 10
    &quot;&quot;&quot;)

from_db_cursor(cur)</code></pre>
<table>
    <thead>
        <tr>
            <th>CustomerId</th>
            <th>My Name☆</th>
        </tr>
    </thead>
    <tbody>
        <tr>
            <td>1</td>
            <td>Luís Gonçalves</td>
        </tr>
        <tr>
            <td>2</td>
            <td>Leonie Köhler</td>
        </tr>
        <tr>
            <td>3</td>
            <td>François Tremblay</td>
        </tr>
        <tr>
            <td>4</td>
            <td>Bjørn Hansen</td>
        </tr>
        <tr>
            <td>5</td>
            <td>František Wichterlová</td>
        </tr>
        <tr>
            <td>6</td>
            <td>Helena Holý</td>
        </tr>
        <tr>
            <td>7</td>
            <td>Astrid Gruber</td>
        </tr>
        <tr>
            <td>8</td>
            <td>Daan Peeters</td>
        </tr>
        <tr>
            <td>9</td>
            <td>Kara Nielsen</td>
        </tr>
        <tr>
            <td>10</td>
            <td>Eduardo Martins</td>
        </tr>
    </tbody>
</table>



<h2 id="distinct">DISTINCT</h2>
<p>중복된 데이터를 제외하고 유니크한 값만 보여줍니다</p>
<pre><code class="language-python"># 원하는 컬럼 앞에 DISTINCT 입력
# SELECT DISTINCT column1, column2 FROM table_name;
cur.execute(&quot;&quot;&quot;
    SELECT DISTINCT country
    FROM customers
    LIMIT 10
    &quot;&quot;&quot;)

from_db_cursor(cur)</code></pre>
<table>
    <thead>
        <tr>
            <th>Country</th>
        </tr>
    </thead>
    <tbody>
        <tr>
            <td>Brazil</td>
        </tr>
        <tr>
            <td>Germany</td>
        </tr>
        <tr>
            <td>Canada</td>
        </tr>
        <tr>
            <td>Norway</td>
        </tr>
        <tr>
            <td>Czech Republic</td>
        </tr>
        <tr>
            <td>Austria</td>
        </tr>
        <tr>
            <td>Belgium</td>
        </tr>
        <tr>
            <td>Denmark</td>
        </tr>
        <tr>
            <td>USA</td>
        </tr>
        <tr>
            <td>Portugal</td>
        </tr>
    </tbody>
</table>



<h2 id="order-by">ORDER BY</h2>
<p>특정 컬럼을 기준으로 데이터를 정렬할 수 있습니다.</p>
<pre><code class="language-python"># SELECT * FROM table_name ORDER BY column1
# LIMIT은 ORDER BY 다음에 작성
cur.execute(&quot;&quot;&quot;
    SELECT *
    FROM customers
    ORDER BY country
    LIMIT 10
    &quot;&quot;&quot;)

from_db_cursor(cur)</code></pre>
<table>
    <thead>
        <tr>
            <th>CustomerId</th>
            <th>FirstName</th>
            <th>LastName</th>
            <th>Company</th>
            <th>Address</th>
            <th>City</th>
            <th>State</th>
            <th>Country</th>
            <th>PostalCode</th>
            <th>Phone</th>
            <th>Fax</th>
            <th>Email</th>
            <th>SupportRepId</th>
        </tr>
    </thead>
    <tbody>
        <tr>
            <td>56</td>
            <td>Diego</td>
            <td>Gutiérrez</td>
            <td>None</td>
            <td>307 Macacha Güemes</td>
            <td>Buenos Aires</td>
            <td>None</td>
            <td>Argentina</td>
            <td>1106</td>
            <td>+54 (0)11 4311 4333</td>
            <td>None</td>
            <td>diego.gutierrez@yahoo.ar</td>
            <td>4</td>
        </tr>
        <tr>
            <td>55</td>
            <td>Mark</td>
            <td>Taylor</td>
            <td>None</td>
            <td>421 Bourke Street</td>
            <td>Sidney</td>
            <td>NSW</td>
            <td>Australia</td>
            <td>2010</td>
            <td>+61 (02) 9332 3633</td>
            <td>None</td>
            <td>mark.taylor@yahoo.au</td>
            <td>4</td>
        </tr>
        <tr>
            <td>7</td>
            <td>Astrid</td>
            <td>Gruber</td>
            <td>None</td>
            <td>Rotenturmstraße 4, 1010 Innere Stadt</td>
            <td>Vienne</td>
            <td>None</td>
            <td>Austria</td>
            <td>1010</td>
            <td>+43 01 5134505</td>
            <td>None</td>
            <td>astrid.gruber@apple.at</td>
            <td>5</td>
        </tr>
        <tr>
            <td>8</td>
            <td>Daan</td>
            <td>Peeters</td>
            <td>None</td>
            <td>Grétrystraat 63</td>
            <td>Brussels</td>
            <td>None</td>
            <td>Belgium</td>
            <td>1000</td>
            <td>+32 02 219 03 03</td>
            <td>None</td>
            <td>daan_peeters@apple.be</td>
            <td>4</td>
        </tr>
        <tr>
            <td>1</td>
            <td>Luís</td>
            <td>Gonçalves</td>
            <td>Embraer - Empresa Brasileira de Aeronáutica S.A.</td>
            <td>Av. Brigadeiro Faria Lima, 2170</td>
            <td>São José dos Campos</td>
            <td>SP</td>
            <td>Brazil</td>
            <td>12227-000</td>
            <td>+55 (12) 3923-5555</td>
            <td>+55 (12) 3923-5566</td>
            <td>luisg@embraer.com.br</td>
            <td>3</td>
        </tr>
        <tr>
            <td>10</td>
            <td>Eduardo</td>
            <td>Martins</td>
            <td>Woodstock Discos</td>
            <td>Rua Dr. Falcão Filho, 155</td>
            <td>São Paulo</td>
            <td>SP</td>
            <td>Brazil</td>
            <td>01007-010</td>
            <td>+55 (11) 3033-5446</td>
            <td>+55 (11) 3033-4564</td>
            <td>eduardo@woodstock.com.br</td>
            <td>4</td>
        </tr>
        <tr>
            <td>11</td>
            <td>Alexandre</td>
            <td>Rocha</td>
            <td>Banco do Brasil S.A.</td>
            <td>Av. Paulista, 2022</td>
            <td>São Paulo</td>
            <td>SP</td>
            <td>Brazil</td>
            <td>01310-200</td>
            <td>+55 (11) 3055-3278</td>
            <td>+55 (11) 3055-8131</td>
            <td>alero@uol.com.br</td>
            <td>5</td>
        </tr>
        <tr>
            <td>12</td>
            <td>Roberto</td>
            <td>Almeida</td>
            <td>Riotur</td>
            <td>Praça Pio X, 119</td>
            <td>Rio de Janeiro</td>
            <td>RJ</td>
            <td>Brazil</td>
            <td>20040-020</td>
            <td>+55 (21) 2271-7000</td>
            <td>+55 (21) 2271-7070</td>
            <td>roberto.almeida@riotur.gov.br</td>
            <td>3</td>
        </tr>
        <tr>
            <td>13</td>
            <td>Fernanda</td>
            <td>Ramos</td>
            <td>None</td>
            <td>Qe 7 Bloco G</td>
            <td>Brasília</td>
            <td>DF</td>
            <td>Brazil</td>
            <td>71020-677</td>
            <td>+55 (61) 3363-5547</td>
            <td>+55 (61) 3363-7855</td>
            <td>fernadaramos4@uol.com.br</td>
            <td>4</td>
        </tr>
        <tr>
            <td>3</td>
            <td>François</td>
            <td>Tremblay</td>
            <td>None</td>
            <td>1498 rue Bélanger</td>
            <td>Montréal</td>
            <td>QC</td>
            <td>Canada</td>
            <td>H2G 1A7</td>
            <td>+1 (514) 721-4711</td>
            <td>None</td>
            <td>ftremblay@gmail.com</td>
            <td>3</td>
        </tr>
    </tbody>
</table>




<pre><code class="language-python"># 2개 이상의 컬럼을 정렬 기준으로 넣을 수도 있음
cur.execute(&quot;&quot;&quot;
    SELECT DISTINCT country, city
    FROM customers
    ORDER BY country, city
    LIMIT 15
    &quot;&quot;&quot;)

from_db_cursor(cur)</code></pre>
<table>
    <thead>
        <tr>
            <th>Country</th>
            <th>City</th>
        </tr>
    </thead>
    <tbody>
        <tr>
            <td>Argentina</td>
            <td>Buenos Aires</td>
        </tr>
        <tr>
            <td>Australia</td>
            <td>Sidney</td>
        </tr>
        <tr>
            <td>Austria</td>
            <td>Vienne</td>
        </tr>
        <tr>
            <td>Belgium</td>
            <td>Brussels</td>
        </tr>
        <tr>
            <td>Brazil</td>
            <td>Brasília</td>
        </tr>
        <tr>
            <td>Brazil</td>
            <td>Rio de Janeiro</td>
        </tr>
        <tr>
            <td>Brazil</td>
            <td>São José dos Campos</td>
        </tr>
        <tr>
            <td>Brazil</td>
            <td>São Paulo</td>
        </tr>
        <tr>
            <td>Canada</td>
            <td>Edmonton</td>
        </tr>
        <tr>
            <td>Canada</td>
            <td>Halifax</td>
        </tr>
        <tr>
            <td>Canada</td>
            <td>Montréal</td>
        </tr>
        <tr>
            <td>Canada</td>
            <td>Ottawa</td>
        </tr>
        <tr>
            <td>Canada</td>
            <td>Toronto</td>
        </tr>
        <tr>
            <td>Canada</td>
            <td>Vancouver</td>
        </tr>
        <tr>
            <td>Canada</td>
            <td>Winnipeg</td>
        </tr>
    </tbody>
</table>



<p>컬럼별로 정렬 순서를 지정할 수 있습니다.</p>
<ul>
<li>ASC: 오름차순 (따로 입력하지 않으면 default로 오름차순)</li>
<li>DESC: 내림차순</li>
</ul>
<pre><code class="language-python"># 컬럼 뒤에 정렬 순서 입력하기 (ASC는 생략 가능)
cur.execute(&quot;&quot;&quot;
    SELECT DISTINCT country, city
    FROM customers
    ORDER BY country ASC, city DESC
    LIMIT 15
    &quot;&quot;&quot;)

from_db_cursor(cur)</code></pre>
<table>
    <thead>
        <tr>
            <th>Country</th>
            <th>City</th>
        </tr>
    </thead>
    <tbody>
        <tr>
            <td>Argentina</td>
            <td>Buenos Aires</td>
        </tr>
        <tr>
            <td>Australia</td>
            <td>Sidney</td>
        </tr>
        <tr>
            <td>Austria</td>
            <td>Vienne</td>
        </tr>
        <tr>
            <td>Belgium</td>
            <td>Brussels</td>
        </tr>
        <tr>
            <td>Brazil</td>
            <td>São Paulo</td>
        </tr>
        <tr>
            <td>Brazil</td>
            <td>São José dos Campos</td>
        </tr>
        <tr>
            <td>Brazil</td>
            <td>Rio de Janeiro</td>
        </tr>
        <tr>
            <td>Brazil</td>
            <td>Brasília</td>
        </tr>
        <tr>
            <td>Canada</td>
            <td>Yellowknife</td>
        </tr>
        <tr>
            <td>Canada</td>
            <td>Winnipeg</td>
        </tr>
        <tr>
            <td>Canada</td>
            <td>Vancouver</td>
        </tr>
        <tr>
            <td>Canada</td>
            <td>Toronto</td>
        </tr>
        <tr>
            <td>Canada</td>
            <td>Ottawa</td>
        </tr>
        <tr>
            <td>Canada</td>
            <td>Montréal</td>
        </tr>
        <tr>
            <td>Canada</td>
            <td>Halifax</td>
        </tr>
    </tbody>
</table>



<h2 id="where">WHERE</h2>
<p>조건에 맞는 데이터만 가져올 수 있습니다.<br>연산자를 이용하여 조건문을 작성할 수 있습니다.</p>
<h3 id="비교-연산자">비교 연산자</h3>
<table>
<thead>
<tr>
<th>연산자</th>
<th>의미</th>
</tr>
</thead>
<tbody><tr>
<td>=</td>
<td>일치하는 경우</td>
</tr>
<tr>
<td>&lt;&gt;<br/>!=</td>
<td>일치하지 않는 경우</td>
</tr>
<tr>
<td>&lt;</td>
<td>해당 값 미만인 경우</td>
</tr>
<tr>
<td>&lt;=</td>
<td>해당 값 이하인 경우</td>
</tr>
<tr>
<td>&gt;</td>
<td>해당 값 초과인 경우</td>
</tr>
<tr>
<td>&gt;=</td>
<td>해당 값 이상인 경우</td>
</tr>
</tbody></table>
<pre><code class="language-python">cur.execute(&quot;&quot;&quot;
    SELECT *
    FROM customers
    WHERE customerid &lt;= 5
    &quot;&quot;&quot;)

from_db_cursor(cur)</code></pre>
<table>
    <thead>
        <tr>
            <th>CustomerId</th>
            <th>FirstName</th>
            <th>LastName</th>
            <th>Company</th>
            <th>Address</th>
            <th>City</th>
            <th>State</th>
            <th>Country</th>
            <th>PostalCode</th>
            <th>Phone</th>
            <th>Fax</th>
            <th>Email</th>
            <th>SupportRepId</th>
        </tr>
    </thead>
    <tbody>
        <tr>
            <td>1</td>
            <td>Luís</td>
            <td>Gonçalves</td>
            <td>Embraer - Empresa Brasileira de Aeronáutica S.A.</td>
            <td>Av. Brigadeiro Faria Lima, 2170</td>
            <td>São José dos Campos</td>
            <td>SP</td>
            <td>Brazil</td>
            <td>12227-000</td>
            <td>+55 (12) 3923-5555</td>
            <td>+55 (12) 3923-5566</td>
            <td>luisg@embraer.com.br</td>
            <td>3</td>
        </tr>
        <tr>
            <td>2</td>
            <td>Leonie</td>
            <td>Köhler</td>
            <td>None</td>
            <td>Theodor-Heuss-Straße 34</td>
            <td>Stuttgart</td>
            <td>None</td>
            <td>Germany</td>
            <td>70174</td>
            <td>+49 0711 2842222</td>
            <td>None</td>
            <td>leonekohler@surfeu.de</td>
            <td>5</td>
        </tr>
        <tr>
            <td>3</td>
            <td>François</td>
            <td>Tremblay</td>
            <td>None</td>
            <td>1498 rue Bélanger</td>
            <td>Montréal</td>
            <td>QC</td>
            <td>Canada</td>
            <td>H2G 1A7</td>
            <td>+1 (514) 721-4711</td>
            <td>None</td>
            <td>ftremblay@gmail.com</td>
            <td>3</td>
        </tr>
        <tr>
            <td>4</td>
            <td>Bjørn</td>
            <td>Hansen</td>
            <td>None</td>
            <td>Ullevålsveien 14</td>
            <td>Oslo</td>
            <td>None</td>
            <td>Norway</td>
            <td>0171</td>
            <td>+47 22 44 22 22</td>
            <td>None</td>
            <td>bjorn.hansen@yahoo.no</td>
            <td>4</td>
        </tr>
        <tr>
            <td>5</td>
            <td>František</td>
            <td>Wichterlová</td>
            <td>JetBrains s.r.o.</td>
            <td>Klanova 9/506</td>
            <td>Prague</td>
            <td>None</td>
            <td>Czech Republic</td>
            <td>14700</td>
            <td>+420 2 4172 5555</td>
            <td>+420 2 4172 5555</td>
            <td>frantisekw@jetbrains.com</td>
            <td>4</td>
        </tr>
    </tbody>
</table>




<pre><code class="language-python">cur.execute(&quot;&quot;&quot;
    SELECT *
    FROM customers
    WHERE state=&#39;SP&#39;
    &quot;&quot;&quot;)

from_db_cursor(cur)</code></pre>
<table>
    <thead>
        <tr>
            <th>CustomerId</th>
            <th>FirstName</th>
            <th>LastName</th>
            <th>Company</th>
            <th>Address</th>
            <th>City</th>
            <th>State</th>
            <th>Country</th>
            <th>PostalCode</th>
            <th>Phone</th>
            <th>Fax</th>
            <th>Email</th>
            <th>SupportRepId</th>
        </tr>
    </thead>
    <tbody>
        <tr>
            <td>1</td>
            <td>Luís</td>
            <td>Gonçalves</td>
            <td>Embraer - Empresa Brasileira de Aeronáutica S.A.</td>
            <td>Av. Brigadeiro Faria Lima, 2170</td>
            <td>São José dos Campos</td>
            <td>SP</td>
            <td>Brazil</td>
            <td>12227-000</td>
            <td>+55 (12) 3923-5555</td>
            <td>+55 (12) 3923-5566</td>
            <td>luisg@embraer.com.br</td>
            <td>3</td>
        </tr>
        <tr>
            <td>10</td>
            <td>Eduardo</td>
            <td>Martins</td>
            <td>Woodstock Discos</td>
            <td>Rua Dr. Falcão Filho, 155</td>
            <td>São Paulo</td>
            <td>SP</td>
            <td>Brazil</td>
            <td>01007-010</td>
            <td>+55 (11) 3033-5446</td>
            <td>+55 (11) 3033-4564</td>
            <td>eduardo@woodstock.com.br</td>
            <td>4</td>
        </tr>
        <tr>
            <td>11</td>
            <td>Alexandre</td>
            <td>Rocha</td>
            <td>Banco do Brasil S.A.</td>
            <td>Av. Paulista, 2022</td>
            <td>São Paulo</td>
            <td>SP</td>
            <td>Brazil</td>
            <td>01310-200</td>
            <td>+55 (11) 3055-3278</td>
            <td>+55 (11) 3055-8131</td>
            <td>alero@uol.com.br</td>
            <td>5</td>
        </tr>
    </tbody>
</table>



<h3 id="between">BETWEEN</h3>
<p>지정한 범위 내의 값이면 참입니다.</p>
<pre><code class="language-python"># BETWEEN a AND b -&gt; a~b 범위 안이면 참
cur.execute(&quot;&quot;&quot;
    SELECT *
    FROM customers
    WHERE customerid BETWEEN 15 AND 20
    &quot;&quot;&quot;)

from_db_cursor(cur)</code></pre>
<table>
    <thead>
        <tr>
            <th>CustomerId</th>
            <th>FirstName</th>
            <th>LastName</th>
            <th>Company</th>
            <th>Address</th>
            <th>City</th>
            <th>State</th>
            <th>Country</th>
            <th>PostalCode</th>
            <th>Phone</th>
            <th>Fax</th>
            <th>Email</th>
            <th>SupportRepId</th>
        </tr>
    </thead>
    <tbody>
        <tr>
            <td>15</td>
            <td>Jennifer</td>
            <td>Peterson</td>
            <td>Rogers Canada</td>
            <td>700 W Pender Street</td>
            <td>Vancouver</td>
            <td>BC</td>
            <td>Canada</td>
            <td>V6C 1G8</td>
            <td>+1 (604) 688-2255</td>
            <td>+1 (604) 688-8756</td>
            <td>jenniferp@rogers.ca</td>
            <td>3</td>
        </tr>
        <tr>
            <td>16</td>
            <td>Frank</td>
            <td>Harris</td>
            <td>Google Inc.</td>
            <td>1600 Amphitheatre Parkway</td>
            <td>Mountain View</td>
            <td>CA</td>
            <td>USA</td>
            <td>94043-1351</td>
            <td>+1 (650) 253-0000</td>
            <td>+1 (650) 253-0000</td>
            <td>fharris@google.com</td>
            <td>4</td>
        </tr>
        <tr>
            <td>17</td>
            <td>Jack</td>
            <td>Smith</td>
            <td>Microsoft Corporation</td>
            <td>1 Microsoft Way</td>
            <td>Redmond</td>
            <td>WA</td>
            <td>USA</td>
            <td>98052-8300</td>
            <td>+1 (425) 882-8080</td>
            <td>+1 (425) 882-8081</td>
            <td>jacksmith@microsoft.com</td>
            <td>5</td>
        </tr>
        <tr>
            <td>18</td>
            <td>Michelle</td>
            <td>Brooks</td>
            <td>None</td>
            <td>627 Broadway</td>
            <td>New York</td>
            <td>NY</td>
            <td>USA</td>
            <td>10012-2612</td>
            <td>+1 (212) 221-3546</td>
            <td>+1 (212) 221-4679</td>
            <td>michelleb@aol.com</td>
            <td>3</td>
        </tr>
        <tr>
            <td>19</td>
            <td>Tim</td>
            <td>Goyer</td>
            <td>Apple Inc.</td>
            <td>1 Infinite Loop</td>
            <td>Cupertino</td>
            <td>CA</td>
            <td>USA</td>
            <td>95014</td>
            <td>+1 (408) 996-1010</td>
            <td>+1 (408) 996-1011</td>
            <td>tgoyer@apple.com</td>
            <td>3</td>
        </tr>
        <tr>
            <td>20</td>
            <td>Dan</td>
            <td>Miller</td>
            <td>None</td>
            <td>541 Del Medio Avenue</td>
            <td>Mountain View</td>
            <td>CA</td>
            <td>USA</td>
            <td>94040-111</td>
            <td>+1 (650) 644-3358</td>
            <td>None</td>
            <td>dmiller@comcast.com</td>
            <td>4</td>
        </tr>
    </tbody>
</table>



<h3 id="in">IN</h3>
<p>지정한 목록에 있는 값 중 하나와 일치하면 참입니다.</p>
<pre><code class="language-python">cur.execute(&quot;&quot;&quot;
    SELECT *
    FROM customers
    WHERE customerid IN (1, 5, 10)
    &quot;&quot;&quot;)

from_db_cursor(cur)</code></pre>
<table>
    <thead>
        <tr>
            <th>CustomerId</th>
            <th>FirstName</th>
            <th>LastName</th>
            <th>Company</th>
            <th>Address</th>
            <th>City</th>
            <th>State</th>
            <th>Country</th>
            <th>PostalCode</th>
            <th>Phone</th>
            <th>Fax</th>
            <th>Email</th>
            <th>SupportRepId</th>
        </tr>
    </thead>
    <tbody>
        <tr>
            <td>1</td>
            <td>Luís</td>
            <td>Gonçalves</td>
            <td>Embraer - Empresa Brasileira de Aeronáutica S.A.</td>
            <td>Av. Brigadeiro Faria Lima, 2170</td>
            <td>São José dos Campos</td>
            <td>SP</td>
            <td>Brazil</td>
            <td>12227-000</td>
            <td>+55 (12) 3923-5555</td>
            <td>+55 (12) 3923-5566</td>
            <td>luisg@embraer.com.br</td>
            <td>3</td>
        </tr>
        <tr>
            <td>5</td>
            <td>František</td>
            <td>Wichterlová</td>
            <td>JetBrains s.r.o.</td>
            <td>Klanova 9/506</td>
            <td>Prague</td>
            <td>None</td>
            <td>Czech Republic</td>
            <td>14700</td>
            <td>+420 2 4172 5555</td>
            <td>+420 2 4172 5555</td>
            <td>frantisekw@jetbrains.com</td>
            <td>4</td>
        </tr>
        <tr>
            <td>10</td>
            <td>Eduardo</td>
            <td>Martins</td>
            <td>Woodstock Discos</td>
            <td>Rua Dr. Falcão Filho, 155</td>
            <td>São Paulo</td>
            <td>SP</td>
            <td>Brazil</td>
            <td>01007-010</td>
            <td>+55 (11) 3033-5446</td>
            <td>+55 (11) 3033-4564</td>
            <td>eduardo@woodstock.com.br</td>
            <td>4</td>
        </tr>
    </tbody>
</table>



<h3 id="like">LIKE</h3>
<p>패턴과 일치하는 경우 참입니다.<br>%와 _를 이용하여 패턴을 지정할 수 있습니다.<br>%와 _는 모든 문자와 매칭되며, %는 문자열, _는 문자 하나를 의미합니다.</p>
<pre><code class="language-python"># 전화번호가 +55로 시작하는 경우
cur.execute(&quot;&quot;&quot;
    SELECT *
    FROM customers
    WHERE phone LIKE &#39;+55%&#39;
    &quot;&quot;&quot;)

from_db_cursor(cur)</code></pre>
<table>
    <thead>
        <tr>
            <th>CustomerId</th>
            <th>FirstName</th>
            <th>LastName</th>
            <th>Company</th>
            <th>Address</th>
            <th>City</th>
            <th>State</th>
            <th>Country</th>
            <th>PostalCode</th>
            <th>Phone</th>
            <th>Fax</th>
            <th>Email</th>
            <th>SupportRepId</th>
        </tr>
    </thead>
    <tbody>
        <tr>
            <td>1</td>
            <td>Luís</td>
            <td>Gonçalves</td>
            <td>Embraer - Empresa Brasileira de Aeronáutica S.A.</td>
            <td>Av. Brigadeiro Faria Lima, 2170</td>
            <td>São José dos Campos</td>
            <td>SP</td>
            <td>Brazil</td>
            <td>12227-000</td>
            <td>+55 (12) 3923-5555</td>
            <td>+55 (12) 3923-5566</td>
            <td>luisg@embraer.com.br</td>
            <td>3</td>
        </tr>
        <tr>
            <td>10</td>
            <td>Eduardo</td>
            <td>Martins</td>
            <td>Woodstock Discos</td>
            <td>Rua Dr. Falcão Filho, 155</td>
            <td>São Paulo</td>
            <td>SP</td>
            <td>Brazil</td>
            <td>01007-010</td>
            <td>+55 (11) 3033-5446</td>
            <td>+55 (11) 3033-4564</td>
            <td>eduardo@woodstock.com.br</td>
            <td>4</td>
        </tr>
        <tr>
            <td>11</td>
            <td>Alexandre</td>
            <td>Rocha</td>
            <td>Banco do Brasil S.A.</td>
            <td>Av. Paulista, 2022</td>
            <td>São Paulo</td>
            <td>SP</td>
            <td>Brazil</td>
            <td>01310-200</td>
            <td>+55 (11) 3055-3278</td>
            <td>+55 (11) 3055-8131</td>
            <td>alero@uol.com.br</td>
            <td>5</td>
        </tr>
        <tr>
            <td>12</td>
            <td>Roberto</td>
            <td>Almeida</td>
            <td>Riotur</td>
            <td>Praça Pio X, 119</td>
            <td>Rio de Janeiro</td>
            <td>RJ</td>
            <td>Brazil</td>
            <td>20040-020</td>
            <td>+55 (21) 2271-7000</td>
            <td>+55 (21) 2271-7070</td>
            <td>roberto.almeida@riotur.gov.br</td>
            <td>3</td>
        </tr>
        <tr>
            <td>13</td>
            <td>Fernanda</td>
            <td>Ramos</td>
            <td>None</td>
            <td>Qe 7 Bloco G</td>
            <td>Brasília</td>
            <td>DF</td>
            <td>Brazil</td>
            <td>71020-677</td>
            <td>+55 (61) 3363-5547</td>
            <td>+55 (61) 3363-7855</td>
            <td>fernadaramos4@uol.com.br</td>
            <td>4</td>
        </tr>
    </tbody>
</table>




<pre><code class="language-python"># 전화번호에 55를 포함하는 경우
cur.execute(&quot;&quot;&quot;
    SELECT *
    FROM customers
    WHERE phone LIKE &#39;%55%&#39;
    &quot;&quot;&quot;)

from_db_cursor(cur)</code></pre>
<table>
    <thead>
        <tr>
            <th>CustomerId</th>
            <th>FirstName</th>
            <th>LastName</th>
            <th>Company</th>
            <th>Address</th>
            <th>City</th>
            <th>State</th>
            <th>Country</th>
            <th>PostalCode</th>
            <th>Phone</th>
            <th>Fax</th>
            <th>Email</th>
            <th>SupportRepId</th>
        </tr>
    </thead>
    <tbody>
        <tr>
            <td>1</td>
            <td>Luís</td>
            <td>Gonçalves</td>
            <td>Embraer - Empresa Brasileira de Aeronáutica S.A.</td>
            <td>Av. Brigadeiro Faria Lima, 2170</td>
            <td>São José dos Campos</td>
            <td>SP</td>
            <td>Brazil</td>
            <td>12227-000</td>
            <td>+55 (12) 3923-5555</td>
            <td>+55 (12) 3923-5566</td>
            <td>luisg@embraer.com.br</td>
            <td>3</td>
        </tr>
        <tr>
            <td>5</td>
            <td>František</td>
            <td>Wichterlová</td>
            <td>JetBrains s.r.o.</td>
            <td>Klanova 9/506</td>
            <td>Prague</td>
            <td>None</td>
            <td>Czech Republic</td>
            <td>14700</td>
            <td>+420 2 4172 5555</td>
            <td>+420 2 4172 5555</td>
            <td>frantisekw@jetbrains.com</td>
            <td>4</td>
        </tr>
        <tr>
            <td>10</td>
            <td>Eduardo</td>
            <td>Martins</td>
            <td>Woodstock Discos</td>
            <td>Rua Dr. Falcão Filho, 155</td>
            <td>São Paulo</td>
            <td>SP</td>
            <td>Brazil</td>
            <td>01007-010</td>
            <td>+55 (11) 3033-5446</td>
            <td>+55 (11) 3033-4564</td>
            <td>eduardo@woodstock.com.br</td>
            <td>4</td>
        </tr>
        <tr>
            <td>11</td>
            <td>Alexandre</td>
            <td>Rocha</td>
            <td>Banco do Brasil S.A.</td>
            <td>Av. Paulista, 2022</td>
            <td>São Paulo</td>
            <td>SP</td>
            <td>Brazil</td>
            <td>01310-200</td>
            <td>+55 (11) 3055-3278</td>
            <td>+55 (11) 3055-8131</td>
            <td>alero@uol.com.br</td>
            <td>5</td>
        </tr>
        <tr>
            <td>12</td>
            <td>Roberto</td>
            <td>Almeida</td>
            <td>Riotur</td>
            <td>Praça Pio X, 119</td>
            <td>Rio de Janeiro</td>
            <td>RJ</td>
            <td>Brazil</td>
            <td>20040-020</td>
            <td>+55 (21) 2271-7000</td>
            <td>+55 (21) 2271-7070</td>
            <td>roberto.almeida@riotur.gov.br</td>
            <td>3</td>
        </tr>
        <tr>
            <td>13</td>
            <td>Fernanda</td>
            <td>Ramos</td>
            <td>None</td>
            <td>Qe 7 Bloco G</td>
            <td>Brasília</td>
            <td>DF</td>
            <td>Brazil</td>
            <td>71020-677</td>
            <td>+55 (61) 3363-5547</td>
            <td>+55 (61) 3363-7855</td>
            <td>fernadaramos4@uol.com.br</td>
            <td>4</td>
        </tr>
        <tr>
            <td>14</td>
            <td>Mark</td>
            <td>Philips</td>
            <td>Telus</td>
            <td>8210 111 ST NW</td>
            <td>Edmonton</td>
            <td>AB</td>
            <td>Canada</td>
            <td>T6G 2C7</td>
            <td>+1 (780) 434-4554</td>
            <td>+1 (780) 434-5565</td>
            <td>mphilips12@shaw.ca</td>
            <td>5</td>
        </tr>
        <tr>
            <td>15</td>
            <td>Jennifer</td>
            <td>Peterson</td>
            <td>Rogers Canada</td>
            <td>700 W Pender Street</td>
            <td>Vancouver</td>
            <td>BC</td>
            <td>Canada</td>
            <td>V6C 1G8</td>
            <td>+1 (604) 688-2255</td>
            <td>+1 (604) 688-8756</td>
            <td>jenniferp@rogers.ca</td>
            <td>3</td>
        </tr>
        <tr>
            <td>36</td>
            <td>Hannah</td>
            <td>Schneider</td>
            <td>None</td>
            <td>Tauentzienstraße 8</td>
            <td>Berlin</td>
            <td>None</td>
            <td>Germany</td>
            <td>10789</td>
            <td>+49 030 26550280</td>
            <td>None</td>
            <td>hannah.schneider@yahoo.de</td>
            <td>5</td>
        </tr>
    </tbody>
</table>




<pre><code class="language-python"># state가 B로 끝나는 2글자인 경우
cur.execute(&quot;&quot;&quot;
    SELECT *
    FROM customers
    WHERE state LIKE &#39;_B&#39;
    &quot;&quot;&quot;)

from_db_cursor(cur)</code></pre>
<table>
    <thead>
        <tr>
            <th>CustomerId</th>
            <th>FirstName</th>
            <th>LastName</th>
            <th>Company</th>
            <th>Address</th>
            <th>City</th>
            <th>State</th>
            <th>Country</th>
            <th>PostalCode</th>
            <th>Phone</th>
            <th>Fax</th>
            <th>Email</th>
            <th>SupportRepId</th>
        </tr>
    </thead>
    <tbody>
        <tr>
            <td>14</td>
            <td>Mark</td>
            <td>Philips</td>
            <td>Telus</td>
            <td>8210 111 ST NW</td>
            <td>Edmonton</td>
            <td>AB</td>
            <td>Canada</td>
            <td>T6G 2C7</td>
            <td>+1 (780) 434-4554</td>
            <td>+1 (780) 434-5565</td>
            <td>mphilips12@shaw.ca</td>
            <td>5</td>
        </tr>
        <tr>
            <td>32</td>
            <td>Aaron</td>
            <td>Mitchell</td>
            <td>None</td>
            <td>696 Osborne Street</td>
            <td>Winnipeg</td>
            <td>MB</td>
            <td>Canada</td>
            <td>R3L 2B9</td>
            <td>+1 (204) 452-6452</td>
            <td>None</td>
            <td>aaronmitchell@yahoo.ca</td>
            <td>4</td>
        </tr>
    </tbody>
</table>




<pre><code class="language-python"># 성이 on으로 끝나는 문자열
cur.execute(&quot;&quot;&quot;
    SELECT *
    FROM customers
    WHERE lastname LIKE &#39;%on&#39;
    &quot;&quot;&quot;)

from_db_cursor(cur)</code></pre>
<table>
    <thead>
        <tr>
            <th>CustomerId</th>
            <th>FirstName</th>
            <th>LastName</th>
            <th>Company</th>
            <th>Address</th>
            <th>City</th>
            <th>State</th>
            <th>Country</th>
            <th>PostalCode</th>
            <th>Phone</th>
            <th>Fax</th>
            <th>Email</th>
            <th>SupportRepId</th>
        </tr>
    </thead>
    <tbody>
        <tr>
            <td>15</td>
            <td>Jennifer</td>
            <td>Peterson</td>
            <td>Rogers Canada</td>
            <td>700 W Pender Street</td>
            <td>Vancouver</td>
            <td>BC</td>
            <td>Canada</td>
            <td>V6C 1G8</td>
            <td>+1 (604) 688-2255</td>
            <td>+1 (604) 688-8756</td>
            <td>jenniferp@rogers.ca</td>
            <td>3</td>
        </tr>
        <tr>
            <td>23</td>
            <td>John</td>
            <td>Gordon</td>
            <td>None</td>
            <td>69 Salem Street</td>
            <td>Boston</td>
            <td>MA</td>
            <td>USA</td>
            <td>2113</td>
            <td>+1 (617) 522-1333</td>
            <td>None</td>
            <td>johngordon22@yahoo.com</td>
            <td>4</td>
        </tr>
        <tr>
            <td>24</td>
            <td>Frank</td>
            <td>Ralston</td>
            <td>None</td>
            <td>162 E Superior Street</td>
            <td>Chicago</td>
            <td>IL</td>
            <td>USA</td>
            <td>60611</td>
            <td>+1 (312) 332-3232</td>
            <td>None</td>
            <td>fralston@gmail.com</td>
            <td>3</td>
        </tr>
        <tr>
            <td>51</td>
            <td>Joakim</td>
            <td>Johansson</td>
            <td>None</td>
            <td>Celsiusg. 9</td>
            <td>Stockholm</td>
            <td>None</td>
            <td>Sweden</td>
            <td>11230</td>
            <td>+46 08-651 52 52</td>
            <td>None</td>
            <td>joakim.johansson@yahoo.se</td>
            <td>5</td>
        </tr>
    </tbody>
</table>




<pre><code class="language-python"># email 도메인이 2글자인 경우 (. 뒤에 2글자인 경우)
cur.execute(&quot;&quot;&quot;
    SELECT *
    FROM customers
    WHERE email LIKE &#39;%.__&#39;
    LIMIT 10
    &quot;&quot;&quot;)

from_db_cursor(cur)</code></pre>
<table>
    <thead>
        <tr>
            <th>CustomerId</th>
            <th>FirstName</th>
            <th>LastName</th>
            <th>Company</th>
            <th>Address</th>
            <th>City</th>
            <th>State</th>
            <th>Country</th>
            <th>PostalCode</th>
            <th>Phone</th>
            <th>Fax</th>
            <th>Email</th>
            <th>SupportRepId</th>
        </tr>
    </thead>
    <tbody>
        <tr>
            <td>1</td>
            <td>Luís</td>
            <td>Gonçalves</td>
            <td>Embraer - Empresa Brasileira de Aeronáutica S.A.</td>
            <td>Av. Brigadeiro Faria Lima, 2170</td>
            <td>São José dos Campos</td>
            <td>SP</td>
            <td>Brazil</td>
            <td>12227-000</td>
            <td>+55 (12) 3923-5555</td>
            <td>+55 (12) 3923-5566</td>
            <td>luisg@embraer.com.br</td>
            <td>3</td>
        </tr>
        <tr>
            <td>2</td>
            <td>Leonie</td>
            <td>Köhler</td>
            <td>None</td>
            <td>Theodor-Heuss-Straße 34</td>
            <td>Stuttgart</td>
            <td>None</td>
            <td>Germany</td>
            <td>70174</td>
            <td>+49 0711 2842222</td>
            <td>None</td>
            <td>leonekohler@surfeu.de</td>
            <td>5</td>
        </tr>
        <tr>
            <td>4</td>
            <td>Bjørn</td>
            <td>Hansen</td>
            <td>None</td>
            <td>Ullevålsveien 14</td>
            <td>Oslo</td>
            <td>None</td>
            <td>Norway</td>
            <td>0171</td>
            <td>+47 22 44 22 22</td>
            <td>None</td>
            <td>bjorn.hansen@yahoo.no</td>
            <td>4</td>
        </tr>
        <tr>
            <td>7</td>
            <td>Astrid</td>
            <td>Gruber</td>
            <td>None</td>
            <td>Rotenturmstraße 4, 1010 Innere Stadt</td>
            <td>Vienne</td>
            <td>None</td>
            <td>Austria</td>
            <td>1010</td>
            <td>+43 01 5134505</td>
            <td>None</td>
            <td>astrid.gruber@apple.at</td>
            <td>5</td>
        </tr>
        <tr>
            <td>8</td>
            <td>Daan</td>
            <td>Peeters</td>
            <td>None</td>
            <td>Grétrystraat 63</td>
            <td>Brussels</td>
            <td>None</td>
            <td>Belgium</td>
            <td>1000</td>
            <td>+32 02 219 03 03</td>
            <td>None</td>
            <td>daan_peeters@apple.be</td>
            <td>4</td>
        </tr>
        <tr>
            <td>9</td>
            <td>Kara</td>
            <td>Nielsen</td>
            <td>None</td>
            <td>Sønder Boulevard 51</td>
            <td>Copenhagen</td>
            <td>None</td>
            <td>Denmark</td>
            <td>1720</td>
            <td>+453 3331 9991</td>
            <td>None</td>
            <td>kara.nielsen@jubii.dk</td>
            <td>4</td>
        </tr>
        <tr>
            <td>10</td>
            <td>Eduardo</td>
            <td>Martins</td>
            <td>Woodstock Discos</td>
            <td>Rua Dr. Falcão Filho, 155</td>
            <td>São Paulo</td>
            <td>SP</td>
            <td>Brazil</td>
            <td>01007-010</td>
            <td>+55 (11) 3033-5446</td>
            <td>+55 (11) 3033-4564</td>
            <td>eduardo@woodstock.com.br</td>
            <td>4</td>
        </tr>
        <tr>
            <td>11</td>
            <td>Alexandre</td>
            <td>Rocha</td>
            <td>Banco do Brasil S.A.</td>
            <td>Av. Paulista, 2022</td>
            <td>São Paulo</td>
            <td>SP</td>
            <td>Brazil</td>
            <td>01310-200</td>
            <td>+55 (11) 3055-3278</td>
            <td>+55 (11) 3055-8131</td>
            <td>alero@uol.com.br</td>
            <td>5</td>
        </tr>
        <tr>
            <td>12</td>
            <td>Roberto</td>
            <td>Almeida</td>
            <td>Riotur</td>
            <td>Praça Pio X, 119</td>
            <td>Rio de Janeiro</td>
            <td>RJ</td>
            <td>Brazil</td>
            <td>20040-020</td>
            <td>+55 (21) 2271-7000</td>
            <td>+55 (21) 2271-7070</td>
            <td>roberto.almeida@riotur.gov.br</td>
            <td>3</td>
        </tr>
        <tr>
            <td>13</td>
            <td>Fernanda</td>
            <td>Ramos</td>
            <td>None</td>
            <td>Qe 7 Bloco G</td>
            <td>Brasília</td>
            <td>DF</td>
            <td>Brazil</td>
            <td>71020-677</td>
            <td>+55 (61) 3363-5547</td>
            <td>+55 (61) 3363-7855</td>
            <td>fernadaramos4@uol.com.br</td>
            <td>4</td>
        </tr>
    </tbody>
</table>]]></description>
        </item>
        <item>
            <title><![CDATA[sqlite3]]></title>
            <link>https://velog.io/@pirate-turtle/sqlite3</link>
            <guid>https://velog.io/@pirate-turtle/sqlite3</guid>
            <pubDate>Wed, 20 Jul 2022 08:08:55 GMT</pubDate>
            <description><![CDATA[<blockquote>
<p>주피터 노트북 파일을 마크다운으로 변환하여 작성한 글입니다.<br>코드는 깃헙에 정리해두었습니다!
<a href="https://github.com/pirate-turtle/SQL">https://github.com/pirate-turtle/SQL</a></p>
</blockquote>
<p>Python에서는 sqlite3 라이브러리를 기본적으로 제공합니다.</p>
<pre><code class="language-python">import sqlite3</code></pre>
<h2 id="연결-생성">연결 생성</h2>
<p>sqlite3 모듈을 사용하기 위해서는 먼저 Connection 객체를 생성하여 데이터베이스에 연결해야합니다.</p>
<pre><code class="language-python"># 원하는 파일명 지정 (존재하지 않는 파일인경우 생성됨)
con = sqlite3.connect(&#39;./database/example.db&#39;)

# 실제 파일 경로 대신 :memory: 를 넘기면 RAM에 임시로 데이터베이스가 생성됨
# con = sqlite3.connect(&#39;:memory:&#39;)</code></pre>
<h2 id="sql-실행">SQL 실행</h2>
<p>Connection 객체를 생성한 다음 Cursor 오브젝트를 생성하여 SQL문을 실행할 수 있도록 합니다.</p>
<pre><code class="language-python"># Cursor 생성
cur = con.cursor()

# 테이블이 이미 있다면 삭제
cur.execute(&quot;DROP TABLE IF EXISTS student&quot;)

# 테이블 생성
cur.execute(&quot;&quot;&quot;
    CREATE TABLE student(
        first_name text,
        last_name text,
        age integer
    )
    &quot;&quot;&quot;)

# 데이터 삽입
# execute 함수는 한번에 하나의 SQL문만 실행 가능
cur.execute(&quot;INSERT INTO student VALUES (&#39;Tomas&#39;, &#39;Train&#39;, 10)&quot;)
cur.execute(&quot;INSERT INTO student VALUES (&#39;Bean&#39;, &#39;Green&#39;, 1)&quot;)</code></pre>
<pre><code>&lt;sqlite3.Cursor at 0x1d459050420&gt;</code></pre><pre><code class="language-python"># 한번에 여러개를 실행하려고 하면 에러 발생
cur.execute(&quot;&quot;&quot;
            INSERT INTO student VALUES (&#39;Tomas&#39;, &#39;Train&#39;, 10);
            INSERT INTO student VALUES (&#39;Bean&#39;, &#39;Green&#39;, 1);
            &quot;&quot;&quot;)</code></pre>
<pre><code>---------------------------------------------------------------------------

Warning                                   Traceback (most recent call last)

~\AppData\Local\Temp/ipykernel_16564/2793874112.py in &lt;module&gt;
      3             INSERT INTO student VALUES (&#39;Tomas&#39;, &#39;Train&#39;, 10);
      4             INSERT INTO student VALUES (&#39;Bean&#39;, &#39;Green&#39;, 1);
----&gt; 5             &quot;&quot;&quot;)


Warning: You can only execute one statement at a time.</code></pre><pre><code class="language-python"># 한번에 여러 SQL문을 실행하고 싶은 경우 executescript 사용하기
cur.executescript(&quot;&quot;&quot;
    DROP TABLE IF EXISTS teacher;
    DROP TABLE IF EXISTS book;

    CREATE TABLE teacher(
        firstname,
        lastname,
        age
    );

    CREATE TABLE book(
        title,
        author,
        published
    );

    INSERT INTO book(title, author, published)
    VALUES (
        &#39;Dirk Gently&#39;&#39;s Holistic Detective Agency&#39;,
        &#39;Douglas Adams&#39;,
        1987
    );
    &quot;&quot;&quot;)</code></pre>
<pre><code>&lt;sqlite3.Cursor at 0x1d459050420&gt;</code></pre><pre><code class="language-python"># 같은 형식의 SQL문에 데이터만 바꿔서 여러번 실행하고 싶은 경우,
# executemany와 제너레이터를 조합하면 좋다
# 메모리에 모두 올라가는 적은 양의 데이터라면 그냥 리스트로 넘겨도 될듯
def data_generator():
    datas = [
                [&#39;Bee&#39;, &#39;Honey&#39;, 3],
                [&#39;Bee&#39;, &#39;Zig&#39;, 5], 
                [&#39;Bob&#39;, &#39;Sponge&#39;, 7]
            ]
    for data in datas:
        yield data

cur.executemany(&quot;INSERT INTO student VALUES (?, ?, ?)&quot;, data_generator())
cur.execute(&quot;SELECT * FROM student&quot;)
cur.fetchall()</code></pre>
<pre><code>[(&#39;Tomas&#39;, &#39;Train&#39;, 10),
 (&#39;Bean&#39;, &#39;Green&#39;, 1),
 (&#39;Bee&#39;, &#39;Honey&#39;, 3),
 (&#39;Bee&#39;, &#39;Zig&#39;, 5),
 (&#39;Bob&#39;, &#39;Sponge&#39;, 7)]</code></pre><h3 id="결과-조회">결과 조회</h3>
<p>SQL 결과를 조회하기 위해서는 Cursor 객체를 iterator로 활용하는 방법,<br>fetchone, fetchmany, fetchall 함수를 이용하는 방법이 있습니다.</p>
<pre><code class="language-python"># Cursor는 iterator객체이므로 순차적으로 값을 불러올 수 있다
cur.execute(&quot;SELECT * FROM student&quot;).rowcount

print(next(cur))
print(next(cur))</code></pre>
<pre><code>(&#39;Tomas&#39;, &#39;Train&#39;, 10)
(&#39;Bean&#39;, &#39;Green&#39;, 1)</code></pre><pre><code class="language-python"># SQL 실행하면 동일한 cursor 객체를 리턴해준다
cur.execute(&quot;SELECT * FROM student&quot;) is cur</code></pre>
<pre><code>True</code></pre><pre><code class="language-python"># 그래서 이렇게 바로 for문에 넣는것도 가능!
for row in cur.execute(&quot;SELECT * FROM student&quot;):
    print(row)</code></pre>
<pre><code>(&#39;Tomas&#39;, &#39;Train&#39;, 10)
(&#39;Bean&#39;, &#39;Green&#39;, 1)
(&#39;Bee&#39;, &#39;Honey&#39;, 3)
(&#39;Bee&#39;, &#39;Zig&#39;, 5)
(&#39;Bob&#39;, &#39;Sponge&#39;, 7)</code></pre><p>fetchone, fetchmany, fetchall 함수를 이용하여 결과를 가져올 경우,<br>이미 조회한 데이터는 다시 함수를 호출해도 조회할 수 없습니다. (다음 데이터부터 가져옴)<br>다시 조회하고 싶다면 SQL문을 다시 실행해야합니다.</p>
<pre><code class="language-python"># fetchone은 실행결과 중 하나의 행만 가져온다
cur.execute(&quot;SELECT * FROM student&quot;)
cur.fetchone()</code></pre>
<pre><code>(&#39;Tomas&#39;, &#39;Train&#39;, 10)</code></pre><pre><code class="language-python"># 한번 더 호출해보면 그 다음 행을 가져온다
cur.fetchone()</code></pre>
<pre><code>(&#39;Bean&#39;, &#39;Green&#39;, 1)</code></pre><pre><code class="language-python"># fetchmany는 실행 결과 중 원하는 개수의 행을 가져올 수 있다
# 원하는 개수보다 적은 행이 남아있으면 남은 행만큼만 가져온다
cur.fetchmany(5)</code></pre>
<pre><code>[(&#39;Bee&#39;, &#39;Honey&#39;, 3), (&#39;Bee&#39;, &#39;Zig&#39;, 5), (&#39;Bob&#39;, &#39;Sponge&#39;, 7)]</code></pre><pre><code class="language-python"># fetchall은 실행 결과 중 남아있는 모든 행을 가져온다
# 남아있는 행이 없으면 빈 리스트 리턴
cur.fetchall()</code></pre>
<pre><code>[]</code></pre><pre><code class="language-python"># 다시 조회하고 싶으면 SQL문을 다시 실행해야한다
cur.execute(&quot;SELECT * FROM student&quot;)
cur.fetchall()</code></pre>
<pre><code>[(&#39;Tomas&#39;, &#39;Train&#39;, 10),
 (&#39;Bean&#39;, &#39;Green&#39;, 1),
 (&#39;Bee&#39;, &#39;Honey&#39;, 3),
 (&#39;Bee&#39;, &#39;Zig&#39;, 5),
 (&#39;Bob&#39;, &#39;Sponge&#39;, 7)]</code></pre><h3 id="변경사항-저장">변경사항 저장</h3>
<p>Connection객체의 commit함수로 변경사항을 저장할 수 있습니다.</p>
<pre><code class="language-python"># commit으로 변경사항 저장
con.commit()

# 다시 연결한 다음 확인해보기
con.close()

con = sqlite3.connect(&#39;./database/example.db&#39;)
cur = con.cursor()

# 변경사항이 저장됐다
for row in cur.execute(&quot;SELECT * FROM student&quot;):
    print(row)</code></pre>
<pre><code>(&#39;Tomas&#39;, &#39;Train&#39;, 10)
(&#39;Bean&#39;, &#39;Green&#39;, 1)
(&#39;Bee&#39;, &#39;Honey&#39;, 3)
(&#39;Bee&#39;, &#39;Zig&#39;, 5)
(&#39;Bob&#39;, &#39;Sponge&#39;, 7)</code></pre><h2 id="테이블-보기-좋게-출력하기">테이블 보기 좋게 출력하기</h2>
<h3 id="prettytable">prettytable</h3>
<p>이번 프로젝트에서는 prettytable 모듈을 활용했습니다.<br>pandas를 활용해도 좋겠지만 단순히 SQL 실행 결과만 확인할 것이기 때문에 prettytable로도 충분합니다.</p>
<pre><code class="language-python"># prettytable 모듈 버전 확인
!pip show prettytable | findstr Version

# 리눅스 환경에서는 findstr 말고 grep 사용하기
# !pip show prettytable | grep Version

# 모듈 없는 경우 주석 해제하고 설치하기
# !pip install prettytable</code></pre>
<pre><code>Version: 3.3.0</code></pre><p>Python DB-API를 통해 지원되는 DB모듈의 경우 Cursor 객체를 바로 테이블로 만들 수 있습니다</p>
<pre><code class="language-python">from prettytable import from_db_cursor

cur.execute(&quot;SELECT * FROM student&quot;)
from_db_cursor(cur)</code></pre>
<table>
    <thead>
        <tr>
            <th>first_name</th>
            <th>last_name</th>
            <th>age</th>
        </tr>
    </thead>
    <tbody>
        <tr>
            <td>Tomas</td>
            <td>Train</td>
            <td>10</td>
        </tr>
        <tr>
            <td>Bean</td>
            <td>Green</td>
            <td>1</td>
        </tr>
        <tr>
            <td>Bee</td>
            <td>Honey</td>
            <td>3</td>
        </tr>
        <tr>
            <td>Bee</td>
            <td>Zig</td>
            <td>5</td>
        </tr>
        <tr>
            <td>Bob</td>
            <td>Sponge</td>
            <td>7</td>
        </tr>
    </tbody>
</table>



<h3 id="컬럼명-필드명">컬럼명 (필드명)</h3>
<p>prettytable 모듈을 거치지 않고 특정 테이블의 컬럼명을 알고 싶은 경우 2가지 방법이 있습니다.  </p>
<ul>
<li>PARAGMA 키워드로 스키마 확인하기</li>
<li>Conncetion 객체에 Row 객체 연결하기</li>
</ul>
<p>스키마에서 컬럼명을 확인하는 경우, 특정 인덱스의 열만 가져오는 작업이 필요합니다.</p>
<pre><code class="language-python"># PRAGMA 키워드로 스키마 확인
cur.execute(&quot;PRAGMA table_info(&#39;student&#39;)&quot;)
schema = cur.fetchall()
schema</code></pre>
<pre><code>[(0, &#39;first_name&#39;, &#39;text&#39;, 0, None, 0),
 (1, &#39;last_name&#39;, &#39;text&#39;, 0, None, 0),
 (2, &#39;age&#39;, &#39;integer&#39;, 0, None, 0)]</code></pre><pre><code class="language-python"># 컬럼명만 가져오기
col_names = list(map(lambda x: x[1], schema))
col_names</code></pre>
<pre><code>[&#39;first_name&#39;, &#39;last_name&#39;, &#39;age&#39;]</code></pre><p>Row 객체를 연결하면 더 쉽게 접근이 가능합니다.<br>SQL 실행 결과가 Row 객체로 오게 되는데, keys() 함수로 편리하게 컬럼명을 얻을 수 있습니다.</p>
<pre><code class="language-python"># Row 객체 연결
con.row_factory = sqlite3.Row

# ※연결 후 Cursor 객체를 다시 생성해줘야 함
cur = con.cursor()
cur.execute(&quot;SELECT * FROM student&quot;)
row = cur.fetchone()

# 컬럼명 확인하기
print(&#39;col_name: &#39;, row.keys())</code></pre>
<pre><code>col_name:  [&#39;first_name&#39;, &#39;last_name&#39;, &#39;age&#39;]</code></pre><pre><code class="language-python"># SQL 실행 결과는 Row 객체가 리턴됨
print(row)</code></pre>
<pre><code>&lt;sqlite3.Row object at 0x000001D459163CD0&gt;</code></pre><pre><code class="language-python"># 컬럼명으로 특정 값에 접근 가능
cur.execute(&quot;&quot;&quot;SELECT * FROM student&quot;&quot;&quot;)
row = cur.fetchone()
print(row[&#39;last_name&#39;])

# 행 데이터를 확인하기 위해 형변환
# dict나 list 타입도 가능하지만 값 변경 못하게 tuple로 변환해보기
print(tuple(row))</code></pre>
<pre><code>Train
(&#39;Tomas&#39;, &#39;Train&#39;, 10)</code></pre><h2 id="sqlite_master">sqlite_master</h2>
<p>DB 파일의 테이블에 관한 정보는 마스터 테이블인 sqlite_master에 저장됩니다.</p>
<pre><code class="language-python"># sqlite_master 스키마 확인해보기
cur.execute(&quot;PRAGMA table_info(&#39;sqlite_master&#39;)&quot;)
from_db_cursor(cur)</code></pre>
<table>
    <thead>
        <tr>
            <th>cid</th>
            <th>name</th>
            <th>type</th>
            <th>notnull</th>
            <th>dflt_value</th>
            <th>pk</th>
        </tr>
    </thead>
    <tbody>
        <tr>
            <td>0</td>
            <td>type</td>
            <td>text</td>
            <td>0</td>
            <td>None</td>
            <td>0</td>
        </tr>
        <tr>
            <td>1</td>
            <td>name</td>
            <td>text</td>
            <td>0</td>
            <td>None</td>
            <td>0</td>
        </tr>
        <tr>
            <td>2</td>
            <td>tbl_name</td>
            <td>text</td>
            <td>0</td>
            <td>None</td>
            <td>0</td>
        </tr>
        <tr>
            <td>3</td>
            <td>rootpage</td>
            <td>int</td>
            <td>0</td>
            <td>None</td>
            <td>0</td>
        </tr>
        <tr>
            <td>4</td>
            <td>sql</td>
            <td>text</td>
            <td>0</td>
            <td>None</td>
            <td>0</td>
        </tr>
    </tbody>
</table>




<pre><code class="language-python"># 생성된 데이터베이스에 대한 정보가 저장되어있다
cur.execute(&quot;SELECT * FROM sqlite_master&quot;)
from_db_cursor(cur)</code></pre>
<table>
    <thead>
        <tr>
            <th>type</th>
            <th>name</th>
            <th>tbl_name</th>
            <th>rootpage</th>
            <th>sql</th>
        </tr>
    </thead>
    <tbody>
        <tr>
            <td>table</td>
            <td>student</td>
            <td>student</td>
            <td>2</td>
            <td>CREATE TABLE student(<br>        first_name text,<br>        last_name text,<br>        age integer<br>    )</td>
        </tr>
        <tr>
            <td>table</td>
            <td>teacher</td>
            <td>teacher</td>
            <td>4</td>
            <td>CREATE TABLE teacher(<br>        firstname,<br>        lastname,<br>        age<br>    )</td>
        </tr>
        <tr>
            <td>table</td>
            <td>book</td>
            <td>book</td>
            <td>3</td>
            <td>CREATE TABLE book(<br>        title,<br>        author,<br>        published<br>    )</td>
        </tr>
    </tbody>
</table>
]]></description>
        </item>
        <item>
            <title><![CDATA[[백준] 부분수열의 합 2 (1208번) - Python]]></title>
            <link>https://velog.io/@pirate-turtle/%EB%B0%B1%EC%A4%80-%EB%B6%80%EB%B6%84%EC%88%98%EC%97%B4%EC%9D%98-%ED%95%A9-2-1208%EB%B2%88-Python</link>
            <guid>https://velog.io/@pirate-turtle/%EB%B0%B1%EC%A4%80-%EB%B6%80%EB%B6%84%EC%88%98%EC%97%B4%EC%9D%98-%ED%95%A9-2-1208%EB%B2%88-Python</guid>
            <pubDate>Sat, 25 Jun 2022 13:09:26 GMT</pubDate>
            <description><![CDATA[<h3 id="문제">문제</h3>
<p><a href="https://www.acmicpc.net/problem/1208">https://www.acmicpc.net/problem/1208</a></p>
<h3 id="아이디어">아이디어</h3>
<blockquote>
<p><a href="https://ku-hug.tistory.com/190">https://ku-hug.tistory.com/190</a>
위 블로그 아이디어 참고</p>
</blockquote>
<ul>
<li>수열을 반으로 나누고 합이 정수 S가 되는 부분수열을 구한다.<ul>
<li>왼쪽에서 나오는 경우의 수</li>
<li>오른쪽에서 나오는 경우의 수</li>
<li>왼쪽과 오른쪽에서 각각 하나씩 골랐을 때 나오는 경우의 수<br/></li>
</ul>
</li>
<li>나는 defaultdict를 이용해서 특정 합이 나오는 경우의 수를 저장했는데, 
위 블로그에서는 bisect 라이브러리(이분탐색)를 활용해서 경우의 수를 셌다. 
이런 방법도 있다니..! 신기..!</li>
</ul>
<h3 id="코드">코드</h3>
<pre><code class="language-python">from sys import stdin
from itertools import combinations
from collections import defaultdict

input = stdin.readline
n, s = map(int, input().split())
arr = list(map(int, input().split()))


# 부분수열 합 구하기
def get_sub_sum(arr:list, result:defaultdict):
    for count in range(1, len(arr)+1):
        for combi in combinations(arr, count):
            c_sum = sum(combi)
            result[c_sum] += 1


# defaultdict를 이용해서 특정 합이 나오는 경우의 수 count
sub_sum1 = defaultdict(int)
sub_sum2 = defaultdict(int)

get_sub_sum(arr[n//2:], sub_sum1)
get_sub_sum(arr[:n//2], sub_sum2)

# 각 부분 수열에 S가 있는 경우 구하기
answer = sub_sum1[s] + sub_sum2[s]


# 두 부분수열을 더해서 S가 나오는 경우의 수 구하기
for s1 in sub_sum1:
    if s-s1 in sub_sum2:
        answer += sub_sum1[s1] * sub_sum2[s-s1]


print(answer)</code></pre>
]]></description>
        </item>
        <item>
            <title><![CDATA[[백준] 부분수열의 합 (14225번) - Python]]></title>
            <link>https://velog.io/@pirate-turtle/%EB%B0%B1%EC%A4%80-%EB%B6%80%EB%B6%84%EC%88%98%EC%97%B4%EC%9D%98-%ED%95%A9-14225%EB%B2%88-Python-qvbmp7xk</link>
            <guid>https://velog.io/@pirate-turtle/%EB%B0%B1%EC%A4%80-%EB%B6%80%EB%B6%84%EC%88%98%EC%97%B4%EC%9D%98-%ED%95%A9-14225%EB%B2%88-Python-qvbmp7xk</guid>
            <pubDate>Sat, 25 Jun 2022 10:45:19 GMT</pubDate>
            <description><![CDATA[<h3 id="문제">문제</h3>
<p><a href="https://www.acmicpc.net/problem/14225">https://www.acmicpc.net/problem/14225</a></p>
<h3 id="아이디어">아이디어</h3>
<ul>
<li>combinations 라이브러리를 이용하여 수열에서 숫자 고르기<ul>
<li>수열 전체 길이 / 2 까지만 고름</li>
<li>굳이 모든 경우의 수를 구할 필요가 없다!
전체 합에서 고른 수들의 합을 빼면 나머지 반도 구할 수 있다!
<em>(n개의 수 중 a개 만큼 뽑을 때, n개 전체 합 - a개 합 == n-a개 합)</em></li>
</ul>
</li>
<li>자연수 탐색을 빠르게 하기 위해 set에 저장</li>
</ul>
<h3 id="코드">코드</h3>
<pre><code class="language-python">from itertools import combinations

n = int(input())
s = list(map(int, input().split()))

total = sum(s)

nums = set(s)
nums.add(total)

# 수열 길이 / 2 개 까지만 경우의 수 구함
for count in range(1, n//2+1):
    for combi in combinations(s, count):
        num = sum(combi)    # count개 합
        nums.update((num, total-num))   # count 합, n-count 합

# 제일 작은 자연수 탐색
answer = 1
while answer in nums:
    answer += 1

print(answer)
</code></pre>
<h3 id="개선점">개선점</h3>
<ul>
<li>수열 길이에 따라 중복된 합이 나오게 된다 (set에 저장했기 때문에 큰 문제는 X)</li>
</ul>
]]></description>
        </item>
        <item>
            <title><![CDATA[[백준] 숨바꼭질5 17071번 - Python]]></title>
            <link>https://velog.io/@pirate-turtle/%EB%B0%B1%EC%A4%80-%EC%88%A8%EB%B0%94%EA%BC%AD%EC%A7%885-17071%EB%B2%88-Python</link>
            <guid>https://velog.io/@pirate-turtle/%EB%B0%B1%EC%A4%80-%EC%88%A8%EB%B0%94%EA%BC%AD%EC%A7%885-17071%EB%B2%88-Python</guid>
            <pubDate>Fri, 17 Jun 2022 11:07:46 GMT</pubDate>
            <description><![CDATA[<h3 id="문제">문제</h3>
<p><a href="https://www.acmicpc.net/problem/17071">https://www.acmicpc.net/problem/17071</a></p>
<h3 id="처음-아이디어-실패">처음 아이디어 (실패)</h3>
<ul>
<li>1초마다 현재 시점에 수빈이가 있을 수 있는 곳 표시</li>
<li>동생 움직이고 수빈이와 같은 시간에 도착했는지 체크</li>
<li>시간초과함.. 수빈이가 갈 수 있는 곳이 3^n이라서 시간 지날수록 기하급수적으로 늘어서 그런듯..</li>
</ul>
<pre><code class="language-python">N, K = map(int, input().split())

time = 1
move = [0] * 500001
points = {N}

if N != K:
    while K &lt; 500001:
        # 수빈 움직임 추가
        n_points = set()
        for subin in points:
            for nxt in (subin-1, subin+1, subin*2):
                if -1 &lt; nxt &lt; 500001:
                    move[nxt] = time
                    n_points.add(nxt)

        points = n_points

        # 동생 움직이고 잡혔는지 판단
        K += time
        if K &lt; 500001 and time == move[K]:
            break

        time += 1
else:
    time = 0

if K &lt; 500001:
    print(time)
else:
    print(-1)</code></pre>
<h3 id="참고-아이디어">참고 아이디어</h3>
<blockquote>
<p><a href="https://dongchans.github.io/2019/53/">https://dongchans.github.io/2019/53/</a>
<em>위 블로그의 해결방법 2번 참고</em>
<br/></p>
</blockquote>
<ul>
<li>매 초마다 수빈이 방문할 수 있는 곳 체크</li>
<li>방문 한 적 없는 경우 현재 시간 저장. 현재 시간이 짝수인지 홀수인지에 따라 구분해서 저장<em>(+1 -1로 다시 방문할 수 있기 때문에 최소시간만 저장)</em></li>
<li>수빈이가 이전에 이곳을 방문한 적이 있다면 동생 잡을 수 있는 것!</li>
</ul>
<pre><code class="language-python">N, K = map(int, input().split())

time = 1
move = [[-1, -1] for _ in range(500001)]  # 방문 시, 짝수, 홀수 최소 시간 저장
move[N][0] = 0
points = set([N])

if N != K:
    while K &lt; 500001:
        # 수빈 움직임 추가
        n_points = set()
        for subin in points:
            for nxt in (subin-1, subin+1, subin*2):
                if -1 &lt; nxt &lt; 500001:
                    flag = time % 2
                    if move[nxt][flag] &lt; 0:
                        move[nxt][flag] = time
                        n_points.add(nxt)

        points = n_points

        # 동생 움직이고 잡혔는지 판단
        K += time
        if K &lt; 500001:
            flag = time % 2

            # 현재 시간에 동생 잡을 수 있는지 판단
            if move[K][flag] &gt; -1:
                break           

            time += 1
else:
    time = 0

if K &lt; 500001:
    print(time)
else:
    print(-1)</code></pre>
]]></description>
        </item>
        <item>
            <title><![CDATA[[백준] 양념 반 후라이드 반 (16917번) - Python]]></title>
            <link>https://velog.io/@pirate-turtle/%EB%B0%B1%EC%A4%80-%EC%96%91%EB%85%90-%EB%B0%98-%ED%9B%84%EB%9D%BC%EC%9D%B4%EB%93%9C-%EB%B0%98-16917%EB%B2%88-Python</link>
            <guid>https://velog.io/@pirate-turtle/%EB%B0%B1%EC%A4%80-%EC%96%91%EB%85%90-%EB%B0%98-%ED%9B%84%EB%9D%BC%EC%9D%B4%EB%93%9C-%EB%B0%98-16917%EB%B2%88-Python</guid>
            <pubDate>Mon, 13 Jun 2022 07:10:14 GMT</pubDate>
            <description><![CDATA[<h3 id="문제">문제</h3>
<p><a href="https://www.acmicpc.net/problem/16917">https://www.acmicpc.net/problem/16917</a></p>
<h3 id="아이디어">아이디어</h3>
<ul>
<li>양념과 후라이드를 각각 한마리씩 사는 것과 반반 2개를 사는 것 중 어느 것이 더 저렴한지 계산</li>
<li>최소 수량에 딱 맞게 사는 것과 최소 수량 중 더 많은 쪽에 맞춰서 사는 것 중 어느 것이 더 저렴한지 계산</li>
</ul>
<h3 id="코드">코드</h3>
<pre><code class="language-python">a, b, c, x, y = map(int, input().split())

both_min = min(a+b, c+c)
common = min(x, y)
price1 = both_min * common + a * (x-common) + b * (y-common)
price2 = both_min * max(x, y)

print(min(price1, price2))</code></pre>
]]></description>
        </item>
        <item>
            <title><![CDATA[[백준] LCS (9251번) - Python]]></title>
            <link>https://velog.io/@pirate-turtle/%EB%B0%B1%EC%A4%80-LCS-9251%EB%B2%88-Python</link>
            <guid>https://velog.io/@pirate-turtle/%EB%B0%B1%EC%A4%80-LCS-9251%EB%B2%88-Python</guid>
            <pubDate>Mon, 13 Jun 2022 06:41:58 GMT</pubDate>
            <description><![CDATA[<h3 id="문제">문제</h3>
<p><a href="https://www.acmicpc.net/problem/9251">https://www.acmicpc.net/problem/9251</a></p>
<h3 id="아이디어">아이디어</h3>
<ul>
<li>DP</li>
<li>입력 앞에 문자 하나를 추가해서 마진 생성</li>
<li>두 문자열의 길이가 같다는 조건이 없으므로 각각 따로 체크</li>
</ul>
<h3 id="코드">코드</h3>
<pre><code class="language-python">
seq1 = input()
seq2 = input()


# 마진 설정해주기
seq1 = &#39; &#39; + seq1
seq2 = &#39; &#39; + seq2

lcs = [[0] * len(seq2) for _ in range(len(seq1))]


for i in range(1, len(seq1)):
    for j in range(1, len(seq2)):
        if seq1[i] == seq2[j]:
            lcs[i][j] = lcs[i-1][j-1] + 1
        else:
            lcs[i][j] = max(lcs[i-1][j], lcs[i][j-1])


print(lcs[-1][-1])
</code></pre>
]]></description>
        </item>
        <item>
            <title><![CDATA[[백준] 팰린드롬 만들기 (1695번) - Python]]></title>
            <link>https://velog.io/@pirate-turtle/%EB%B0%B1%EC%A4%80-%ED%8C%B0%EB%A6%B0%EB%93%9C%EB%A1%AC-%EB%A7%8C%EB%93%A4%EA%B8%B0-1695%EB%B2%88-Python</link>
            <guid>https://velog.io/@pirate-turtle/%EB%B0%B1%EC%A4%80-%ED%8C%B0%EB%A6%B0%EB%93%9C%EB%A1%AC-%EB%A7%8C%EB%93%A4%EA%B8%B0-1695%EB%B2%88-Python</guid>
            <pubDate>Mon, 13 Jun 2022 06:09:18 GMT</pubDate>
            <description><![CDATA[<h3 id="문제">문제</h3>
<p><a href="https://www.acmicpc.net/problem/1695">https://www.acmicpc.net/problem/1695</a></p>
<h3 id="아이디어">아이디어</h3>
<p>아래 블로그의 아이디어를 참고함
<a href="https://ddiyeon.tistory.com/67">https://ddiyeon.tistory.com/67</a></p>
<p>최장 공통 부분수열<em>(LCS: Longest Common Subsequence)</em> 개념을 응용</p>
<h3 id="코드">코드</h3>
<p>언어를 PyPy3로 설정해야 통과 (Python은 시간초과) </p>
<pre><code class="language-python">
from sys import stdin


input = stdin.readline

length = int(input())
nums = list(map(int, input().split()))


lcs = [[0] * length for _ in range(length)]

for i in range(length):

    start = nums[i]

    for j in range(length):
        end = nums[length - 1 - j]

        if start == end:
            lcs[i][j] = 1

            if i &gt; 0 and j &gt; 0:
                lcs[i][j] += lcs[i-1][j-1]

        else:
            up = lcs[i-1][j] if i &gt; 0 else 0
            left = lcs[i][j-1] if j &gt; 0 else 0
            lcs[i][j] = max(up, left)


print(length - lcs[-1][-1])
</code></pre>
<h3 id="개선점">개선점</h3>
<p>나는 입력 길이에 딱맞게 배열을 만들어서 인덱스 체크가 필요했는데,<br/> length+1 로 생성하고 0을 마진으로 뒀으면 체크할 필요가 없다..ㅠ</p>
]]></description>
        </item>
        <item>
            <title><![CDATA[[백준] 달팽이 (1913번) - Python]]></title>
            <link>https://velog.io/@pirate-turtle/%EB%B0%B1%EC%A4%80-%EB%8B%AC%ED%8C%BD%EC%9D%B4-1913%EB%B2%88-Python</link>
            <guid>https://velog.io/@pirate-turtle/%EB%B0%B1%EC%A4%80-%EB%8B%AC%ED%8C%BD%EC%9D%B4-1913%EB%B2%88-Python</guid>
            <pubDate>Sat, 11 Jun 2022 06:26:49 GMT</pubDate>
            <description><![CDATA[<h3 id="문제">문제</h3>
<ul>
<li><a href="https://www.acmicpc.net/problem/1913">https://www.acmicpc.net/problem/1913</a></li>
</ul>
<h3 id="아이디어">아이디어</h3>
<p><img src="https://velog.velcdn.com/images/pirate-turtle/post/c66903e3-1cd6-4b76-b93a-f81f7c3eef87/image.jpeg" alt=""></p>
<ul>
<li>중심에서 시작</li>
<li>이전 숫자로부터 한방향으로 n칸씩 움직이면서 숫자 표시<ul>
<li>오른쪽 방향과 왼쪽 방향은 움직이는 칸 수가 이전 방향과 같음<br/><em>(위쪽 = 오른쪽,  아래쪽 = 왼쪽)</em></li>
<li>위쪽 방향과 아래쪽 방향은 움직이는 칸 수가 이전 방향보다 +1 </li>
</ul>
</li>
</ul>
<h3 id="코드">코드</h3>
<p>Point</p>
<ul>
<li>현재까지 방향전환을 몇 번 했는지 count에 저장함.</li>
<li>이 방향으로 몇칸까지 움직여야하는가 == count // 2 + 1<br/><em>(4개 방향을 2개로 묶어주기 위해 2로 나누고 시작 숫자 1 더함)</em></li>
<li>중심에 1을 넣고 반복문으로 들어가기 때문에 찾고자 하는 수가 1인 경우는 미리 체크</li>
<li>이동하다가 배열 범위 초과할 수 있으므로 숫자 체크하면서 반복문 돌기</li>
</ul>
<pre><code class="language-python">
from sys import stdin


input = stdin.readline
last = int(input())
find = int(input())


board = [[0] * last for _ in range(last)]

num = 1
count = -1
i = j = last // 2
last = last ** 2 + 1


board[i][j] = num
num += 1

coordinate = &#39;&#39; if find != 1 else f&#39;{i+1} {j+1}&#39;

while num &lt; last:
    for _i, _j in ((-1, 0), (0, 1), (1, 0), (0, -1)):
        count += 1
        for _ in range(count//2+1):
            if num == last:
                break
            i += _i
            j += _j
            board[i][j] = num

            if num == find:
                coordinate = f&#39;{i+1} {j+1}&#39;

            num += 1

        if num == last:
            break


for line in board:
    print(*line, sep=&#39; &#39;)

print(coordinate)
</code></pre>
]]></description>
        </item>
        <item>
            <title><![CDATA[차원의 저주와 PCA]]></title>
            <link>https://velog.io/@pirate-turtle/%EC%B0%A8%EC%9B%90%EC%9D%98-%EC%A0%80%EC%A3%BC%EC%99%80-PCA</link>
            <guid>https://velog.io/@pirate-turtle/%EC%B0%A8%EC%9B%90%EC%9D%98-%EC%A0%80%EC%A3%BC%EC%99%80-PCA</guid>
            <pubDate>Thu, 02 Dec 2021 05:26:11 GMT</pubDate>
            <description><![CDATA[<h2 id="차원의-저주">차원의 저주</h2>
<p>데이터의 특징(Feature)이 너무 많아서 성능이 저하되는 현상입니다.
차원이 높아질수록 데이터 사이의 거리가 멀어져서 패턴을 찾기 힘들어집니다. (Sparse해짐)
<img src="https://images.velog.io/images/pirate-turtle/post/c62f5603-dc94-438c-9cf6-4ef93065dc07/image.png" alt=""><em>(데이터의 차원을 하나 더 늘렸더니 거리가 멀어지는 모습)</em></p>
<h3 id="해결-방법">해결 방법</h3>
<ul>
<li>데이터를 더 많이 모아서 데이터의 밀도를 높여주기</li>
<li>차원을 축소해주기 (PCA(Principal Components Analysis) 등의 방법을 사용)  </li>
</ul>
<br/>

<h2 id="pca-principle-component-analysis">PCA (Principle Component Analysis)</h2>
<ul>
<li>고차원의 데이터를 저차원으로 축소하는 방법입니다.</li>
<li>데이터에 feature가 많은 경우 모든 feature가 결과에 중요한 영향을 끼치는 것은 아니기 때문에, 가장 중요한 feature들을 골라냅니다. 이를 데이터 압축 기법으로 볼 수 있습니다.
분산을 최대로 보존할 수 있는 초평면을 선택해야 정보를 가장 많이 유지할 수 있습니다.</li>
<li>높은 주성분들만 선택하면서 정보 설명력이 낮은 노이즈 컬럼을 제거하기 때문에 노이즈 제거 기법으로 불리기도 합니다.</li>
</ul>
<p><img src="https://images.velog.io/images/pirate-turtle/post/bfb9a918-56b4-47af-bf4d-46120040c5ce/image.png" alt=""></p>
<h2 id="reference">Reference</h2>
<ul>
<li><a href="https://modern-manual.tistory.com/4">https://modern-manual.tistory.com/4</a></li>
<li><a href="https://bioinformaticsandme.tistory.com/197">https://bioinformaticsandme.tistory.com/197</a></li>
<li><a href="https://butter-shower.tistory.com/210">https://butter-shower.tistory.com/210</a></li>
<li><a href="https://bong-sik.tistory.com/22">https://bong-sik.tistory.com/22</a></li>
</ul>
]]></description>
        </item>
        <item>
            <title><![CDATA[Data Normalization이란?]]></title>
            <link>https://velog.io/@pirate-turtle/Data-Normalization%EC%9D%B4%EB%9E%80</link>
            <guid>https://velog.io/@pirate-turtle/Data-Normalization%EC%9D%B4%EB%9E%80</guid>
            <pubDate>Wed, 01 Dec 2021 03:58:31 GMT</pubDate>
            <description><![CDATA[<h2 id="data-normalization">Data Normalization</h2>
<p>아래 그래프를 보면, 상대적으로 작은 범위의 Feature는 범위가 큰 쪽에 비해 변화가 잘 보이지 않습니다.
이런 경우 모델은 범위가 더 큰 Feature를 중요하게 보게 됩니다.
이 데이터의 변화에 중요한 것은 범위가 큰 Feature라고 보고 가중치가 편향되는 것입니다.</p>
<ul>
<li>Data의 Feature 별 Scale(범위) 차이가 큰 경우 나타날 수 있는 문제
<em>(예시: 집의 방 개수 (1~20)와 지어진 시기(0~100))</em>
<img src="https://images.velog.io/images/pirate-turtle/post/61bbd836-808b-4c3d-bc65-c9998eec94e8/image.png" alt=""></li>
</ul>
<p>각 Feature를 동일한 중요도로 판단할 수 있도록, 범위를 비슷하게 변환해주는 것이 Data Normalization입니다.</p>
<ul>
<li>각 Feature를 0~1 범위로 동일하게 Normaliztion한 결과
<img src="https://images.velog.io/images/pirate-turtle/post/1274e684-cb5b-4043-b836-73b9f8ed11eb/image.png" alt=""></li>
</ul>
<ul>
<li>Reference<ul>
<li><a href="https://hleecaster.com/ml-normalization-concept/">https://hleecaster.com/ml-normalization-concept/</a></li>
<li><a href="https://skyil.tistory.com/50">https://skyil.tistory.com/50</a></li>
</ul>
</li>
</ul>
]]></description>
        </item>
    </channel>
</rss>