• 회원가입
  • 로그인
  • 구글아이디로 로그인

[mysql] Python - MySQL Limit (데이터 출력개수)

2417  

목차

  1. LIMIT 키워드 - 데이터 출력 개수
  2. OFFSET 키워드 - 출력 시작 위치 지정

 

LIMIT 키워드 - 데이터 출력 개수

※ 5개의 첫 번째 데이터 선택 : LIMIT 5

 

import mysql.connector


mydb = mysql.connector.connect(

  host="localhost",

  user="root",

  password="autoset",

  database="hz"

)


mycursor mydb.cursor()

mycursor.execute("SELECT * FROM hz_member LIMIT 5")

myresult mycursor.fetchall()

for x in myresult:

  print(x)

 

 

OFFSET 키워드 - 출력 시작 위치 지정

(예)  처음 2개 제외 (= 즉, 3번째 부터) 후, 5개 가져오기.

 

LIMIT 5 OFFSET 2

또는,

LIMIT 2, 5

 

주의: 2번째부터 시작 의미 X.


[방법1] - LIMIT 5 OFFSET 2

 

import mysql.connector


mydb = mysql.connector.connect(

  host="localhost",

  user="root",

  password="autoset",

  database="hz"

)


mycursor = mydb.cursor()

mycursor.execute("SELECT * FROM hz_member LIMIT 5 OFFSET 2")

myresult = mycursor.fetchall()

for x in myresult:

  print(x)

 


[방법2] - LIMIT 2, 5 ★

 

import mysql.connector 


mydb = mysql.connector.connect(

  host="localhost",

  user="root",

  password="autoset",

  database="hz"

)


mycursor mydb.cursor()

mycursor.execute("SELECT * FROM hz_member LIMIT 2, 5")

myresult mycursor.fetchall()

for x in myresult:

  print(x)

 



분류 제목
mongodb Python - MongoDB Limit (데이터 출력개수)
module Python - random 모듈 메서드 종류
module Python - random.seed() 메서드 - 난수 생성기 초기화 (= seed메서드 = 시드)
module Python - random.getstate() 메서드 - 난수 생성기 현재 상태 반환. (= getstat…
module Python - random.setstate() 메서드 - 난수 생성기 상태 복원. (= setstate메서…
module Python - random.getrandbits() 메서드 ★ - 지정 bit 크기의 정수 반환. (= g…
module Python - random.randrange() 메서드 ★★ - 지정 범위 안에서 정수형 난수 반환. (=…
module Python - random.randint() 메서드 ★★ - 지정 범위 안 int형 난수 생성. (= ra…
module Python - random.choice() 메서드 ★★ - 요소 랜덤 반환. (= choice메서드 = 초…
module Python - random.choices() 메서드 - 가중치 반영해 랜덤 요소 반환. (= choices…
module Python - random.shuffle() 메서드 ★★ - 요소 순서 뒤섞기. (= 순서 랜덤 = shu…
module Python - random.sample() 메서드 ★ - 일부 요소 랜덤 선택. (= sample메서드 =…
module Python - random.random() 메서드 ★ - 0 ~ 1 사이 부동소수 랜덤 반환. (= ran…
module Python - random.uniform() 메서드 ★ - 지정 범위 안 랜덤 부동소수 반환. (= uni…
module Python - random.triangular() 메서드 - 지정 범위 안 가중치 반영 랜덤 부동소수 반환…
module Python - random.betavariate() 메서드 △ - 베타분포 (통계용) 기반 0~1 사이 랜…
module Python - random.expovariate() 메서드 △ - 지수분포 (통계용) 기반 랜덤 부동소수 …
module Python - random.gammavariate() 메서드 △ - 감마분포 (통계용) 기반 랜덤 부동소수…
module Python - random.gauss() 메서드 △ - 가우스분포 (확률이론용) 기반 랜덤 부동소수 반환.
module Python - random.lognormvariate() 메서드 △ - 로그정규분포 (확률이론용) 기반 랜…
4/24
목록
찾아주셔서 감사합니다. Since 2012