_ | 覦覈襦 | 豕蠏手 | 殊螳 | 譯殊碁
FrontPage › DB一危一所鍵

Contents

1
2 anaconda pyodbc install
3 pyodbc: 蠏谿 覯
4 pandas 伎


1 #

  • localhost microsoft sql server螳 れ ( PC 2016 Developer Edition れ)
  • pubs 一危磯伎り り 螳

2 anaconda pyodbc install #

conda install -c anaconda pyodbc=3.0.10

3 pyodbc: 蠏谿 覯 #

Windows OS ODBC誤 讌 . 蠏碁 蟯 り 螳覃 蟆. Windows OS ODBC誤 る conn = pyodbc.connect(r'DSN=mynewdsn;UID=user;PWD=password') 螳 覃 . DSN Data Source Names 曙
import pyodbc
conn = pyodbc.connect(driver='{SQL Server}', host='localhost,1433', database='pubs', user='id', password='pass')
cursor = conn.cursor()
cursor.execute("""
    select  
        type
    ,   count(*) cnt
    from dbo.titles
    group by
        type
    order by 2 desc
""")
rows = cursor.fetchall()
for row in rows:
    print (row.type, row.cnt)

4 pandas 伎 #

import pandas.io.sql as sql
import pyodbc
conn = pyodbc.connect(driver='{SQL Server}', host='localhost,1433', database='pubs', user='id', password='pass')

rows = sql.read_sql("""
    select  
        type
    ,   count(*) cnt
    from dbo.titles
    group by
        type
    order by 2 desc
"""
, conn)
print (rows)

蠍 蠍郁鍵..
企: : るジ讓曙 襦螻豺 企Ν 譯殊語. 襦螻豺
EditText : Print : Mobile : FindPage : DeletePage : LikePages : Powered by MoniWiki : Last modified 2018-04-13 23:12:54

殊 貍螳 螻 蟆 . (碁狩一一)