hognkun
hognkun

Reputation: 337

how to change mysql concat code to pymysql code

this is my mysql code

select ID, GROUP_CONCAT(CONCAT('{R_ICODE:"', R_ICODE, '", RANK:"',RANK,'"}')) list from RESULT where USER_ID='[email protected]' group by ID;

and this is my pymysql code

cursor.execute("ID, GROUP_CONCAT(CONCAT('{R_ICODE:"', R_ICODE, '", RANK:"', RANK, '"}')) list from RESULT where USER_ID='[email protected]' group by ID")

when i ran the pymysql code i got the syntex error so if someones knows the right way plz teach me thank you

Upvotes: 1

Views: 239

Answers (1)

Ed Bangga
Ed Bangga

Reputation: 13006

first, you missed your select statement, 2nd is you need to escape your double quotes.

cursor.execute("SELECT ID
    , GROUP_CONCAT(CONCAT('{R_ICODE:\"', R_ICODE, '\", RANK:"', RANK, '\"}')) list 
    FROM RESULT WHERE USER_ID='[email protected]' group by ID")

Upvotes: 1

Related Questions