按多个值筛选数据 SQL
Filtering Data by multiple value SQL
我喜欢使用 sql 查询 query/filter 一些具有多个值的数据。但我什么也没得到。
这是我的代码。
gd = cal.get_date()
dfd = datetime.strptime(gd, '%m/%d/%y').strftime('%Y-%m-%d')
slspath = ('C:\shgcgr\RMWIN b4 patch 12.22.21\SLS' + my + '.DBF')
slsdbf = DBF(slspath)
slsframe = DataFrame(iter(slsdbf))
dinerc = '1,4,5,7,8,13,14'
lunchdi = ps.sqldf("SELECT SUM(slsframe.total) AS 'netsales_for_lunch' From slsframe Where open_time >= '12:00:00' And open_time < '13:59:59' And date = '" + dfd + "'" + "And rev_center = '" + dinerc + "'")
lunchdidf = DataFrame(lunchdi)
print(lunchdidf)
提前致谢。
dinerc 似乎是 rev_centers 的列表,因此您可能需要使用 IN 而不是 = ,试试这个:
lunchdi = ps.sqldf("SELECT SUM(slsframe.total) AS 'netsales_for_lunch' From slsframe Where open_time >= '12:00:00' And open_time < '13:59:59' And date = '" + dfd + "'" + "And rev_center IN (" + dinerc + ")")
我喜欢使用 sql 查询 query/filter 一些具有多个值的数据。但我什么也没得到。 这是我的代码。
gd = cal.get_date()
dfd = datetime.strptime(gd, '%m/%d/%y').strftime('%Y-%m-%d')
slspath = ('C:\shgcgr\RMWIN b4 patch 12.22.21\SLS' + my + '.DBF')
slsdbf = DBF(slspath)
slsframe = DataFrame(iter(slsdbf))
dinerc = '1,4,5,7,8,13,14'
lunchdi = ps.sqldf("SELECT SUM(slsframe.total) AS 'netsales_for_lunch' From slsframe Where open_time >= '12:00:00' And open_time < '13:59:59' And date = '" + dfd + "'" + "And rev_center = '" + dinerc + "'")
lunchdidf = DataFrame(lunchdi)
print(lunchdidf)
提前致谢。
dinerc 似乎是 rev_centers 的列表,因此您可能需要使用 IN 而不是 = ,试试这个:
lunchdi = ps.sqldf("SELECT SUM(slsframe.total) AS 'netsales_for_lunch' From slsframe Where open_time >= '12:00:00' And open_time < '13:59:59' And date = '" + dfd + "'" + "And rev_center IN (" + dinerc + ")")