我使用mysql sql查询结果,没关系,但是我将sql复制到pandas并使用pandas读取sql查询,第一个查询结果不是mysql结果,更多执行结果是正确的
SELECT
score,
rank
FROM
(
SELECT
score,
@rank : = IF(@score = score , @rank , @rank + 1) rank,
@score : = score
FROM
(
SELECT
score
FROM
reports
ORDER BY
score DESC)
t1,
(select
@rank : = 0)t2
ORDER BY score DESC)mp
结果正确:
+----------+-------+
| score | rank |
+----------+-------+
|100 | 1 |
|100 | 1 |
|100 | 1 |
|99 | 2 |
|99 | 2 |
|98 | 3 |
|90 | 4 |
+----------+-------+
我使用pandas读取sql,使用db引擎是pymysql + mysql,pandas版本0.23.4
pd.read_sql(sql, db.engine)
第一个结果:
+----------+-------+
| score | rank |
+----------+-------+
|100 | 1 |
|100 | 2 |
|100 | 3 |
|99 | 4 |
|99 | 5 |
|98 | 6 |
|90 | 7 |
+----------+-------+
然后第二次执行读取sql:
+----------+-------+
| score | rank |
+----------+-------+
|100 | 1 |
|100 | 1 |
|100 | 1 |
|99 | 2 |
|99 | 2 |
|98 | 3 |
|90 | 4 |
+----------+-------+
我更改了read_sql_query
,但问题仍然相同。
如何更改熊猫配置,只需查询相同的mysql查询,谢谢