■ SQlite3 내장 집계 함수를 사용하는 방법을 보여준다.
▶ 예제 코드 (PY)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
import sqlite3 connection = sqlite3.connect(":memory:") cursor = connection.cursor() cursor.execute("CREATE TABLE PHONE_BOOK (NAME TEXT, AGE INTEGER);") tuple1 = (("Tom", 24), ("Derick", 30), ("Peter", 53), ("Jane", 29)) cursor.executemany("INSERT INTO PHONE_BOOK VALUES (?, ?);", tuple1) cursor.execute("SELECT LENGTH(NAME), UPPER(NAME), LOWER(NAME) FROM PHONE_BOOK;") for rowTuple in cursor: print(rowTuple) print() cursor.execute("SELECT MAX(AGE), MIN(AGE), SUM(AGE) FROM PHONE_BOOK;") for rowTuple in cursor: print(rowTuple) print() cursor.execute("SELECT COUNT(*), RANDOM(*) FROM PHONE_BOOK;") for rowTuple in cursor: print(rowTuple) """ (3, 'TOM', 'tom') (6, 'DERICK', 'derick') (5, 'PETER', 'peter') (4, 'JANE', 'jane') (53, 24, 136) (4, -1899594893834596166) """ |