ValueError:索引798处不支持的格式字符'P'(0x50)

时间:2019-04-26 06:38:02

标签: python mysql mysql-python

我正在尝试执行查询以通过Python使用SQLQuery搜索数据库中的4个表。每次我尝试执行以下字符串作为查询时,都会出现上述错误。

data2 = pd.read_sql("SELECT DateTime, vManagedEntity.DisplayName, vPerformanceRule.ObjectName, vPerformanceRule.CounterName, vPerformanceRuleInstance.InstanceName, SampleCount,AverageValue, MinValue, MaxValue FROM Perf.vPerfHourly INNER JOIN vPerformanceRuleInstance ON Perf.vPerfHourly.PerformanceRuleInstanceRowId =vPerformanceRuleInstance.PerformanceRuleInstanceRowId INNER JOIN vPerformanceRule ON vPerformanceRuleInstance.RuleRowId = vPerformanceRule.RuleRowId INNER JOIN vRelationship ON Perf.vPerfHourly.ManagedEntityRowId = vRelationship.TargetManagedEntityRowId INNER JOIN vManagedEntity ON vRelationship.SourceManagedEntityRowId =vManagedEntity.ManagedEntityRowId WHERE vPerformanceRule.ObjectName in ('Processor', 'Memory', 'Network Adapter', 'System', 'LogicalDisk') AND vPerformanceRule.CounterName in ('% Processor Time', 'Available Mbytes', 'Pages/sec', 'PercentBandwidthUsedTotal', 'Bytes Total/sec', 'Processor Queue Length', '% Free Space', 'Avg. Disk sec/Transfer', 'Current Disk Queue Length') AND LEFT(DisplayName,7) not in ('Active ', 'AD Doma', 'Windows ') AND (DateTime BETWEEN '%s' and '%s')" % (maxDate,currentTime),cnxn)

我验证了各种论坛,但无法解决此问题,如果删除maxDate和CurrentTime参数,则相同的查询有效。我在这里想念什么。

1 个答案:

答案 0 :(得分:1)

似乎您将%放在错误的位置

 ....AND vPerformanceRule.CounterName in ('% Processor Time', 'Available Mbytes',.....

尝试删除

....AND vPerformanceRule.CounterName in ('Processor Time', 'Available Mbytes', ....

或逃脱