server = "UAT101"
db = "mydb"
con = pyodbc.connect('DRIVER={SQL Server};SERVER=' + server + ';DATABASE=' + db +';Uid=uat101_read;Pwd=*****')
max_week = pd.read_sql("select max(FWEEK) from mytable", con).astype('int')
max_week = max_week.iloc[0].astype('str')
min_week = pd.read_sql("select min(FWEEK) from SOE_DC_ML_8K.dbo.RAWDATA_DC_CONSOLIDATED where FWEEK in (select distinct top 2 FWEEK from mytable order by FWEEK desc)", con).astype('int')
min_week = min_week.iloc[0].astype('str')
query = "Select [FWEEK],[DPS_NUM] from mytable where (fweek = '"+max_week+"' or (fweek = '"+min_week+"' and NEW_DPS_FLG = '1'))"
df = pd.read_sql(query, con)
DatabaseError:在sql上执行失败-选择 [FWEEK],[DPS_NUM],[COMMODITYDESC],[SYST ...名称:0,dtype:object': 要执行的第一个参数必须是字符串或Unicode查询。
执行df = pd.read_sql(query, con)
语句时出现错误