利用python筛选出当天的数据

发布于 2021-12-04 06:55:49 字数 1942 浏览 909 评论 1

 


import pymssql
import pandas as pd
###连接sql sever并读取数据到dataframe
conn = pymssql.connect('fghdfhgn', 'sa', 'hgjfhg', '57574')
cursor = conn.cursor()

#########读取当天的数据###
sql = 'select * from RSS where FDate=2018-11-21'
test = pd.read_sql(sql, conn)

DatabaseError: Execution failed on sql 'select * from RSS where FDate=2018-11-21': (206, b'Operand type clash: date is incompatible with intDB-Lib error message 20018, severity 16:nGeneral SQL Server error: Check messages from the SQL Servern')
##############

sql = '''select * from RSS where FDate(checktime,'%Y-%m-%d')=2018-11-21'''
test = pd.read_sql(sql, conn)
DatabaseError: Execution failed on sql 'select * from RSS where FDate(checktime,'%Y-%m-%d')=2018-11-21': (195, b"'FDate' is not a recognized built-in function name.DB-Lib error message 20018, severity 15:nGeneral SQL Server error: Check messages from the SQL Servern")

####
sql = 'select * from RSS where to_days(FDate) = to_days(now())'
test = pd.read_sql(sql, conn)

DatabaseError: Execution failed on sql 'select * from RSS where to_days(FDate) = to_days(now())': (195, b"'to_days' is not a recognized built-in function name.DB-Lib error message 20018, severity 15:nGeneral SQL Server error: Check messages from the SQL Servern")
########
sql = 'SELECT * FROM RSS where DATEDIFF(day,inputdate,GETDATE())=0'

test = pd.read_sql(sql, conn)
DatabaseError: Execution failed on sql 'SELECT * FROM RSS where DATEDIFF(day,inputdate,GETDATE())=0': (207, b"Invalid column name 'inputdate'.DB-Lib error message 20018, severity 16:nGeneral SQL Server error: Check messages from the SQL Servern")
#############

出错信息:DatabaseError: Execution failed on sql 'select * from RSS where datediff(day,ordTime,getdate()-1)=0 ': (207, b"Invalid column name 'ordTime'.DB-Lib error message 20018, severity 16:nGeneral SQL Server error: Check messages from the SQL Servern")

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

顾挽 2021-12-04 17:26:21

 没有加入列


sql = 'select * from RSS where DateDiff(dd,FDate,getdate())=0'

 

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文