Pymysql where clause triple in list

Asked 2 years ago, Updated 2 years ago, 30 views

For example, A = [[1,a],[2,b],[3,c]] and
Myqldb has Table X (column1, coulmn2) select X.column1, X.column2 where [X.column1, X.column2] in A I'd like to write a query that means, so please tell me how to fix it here to fit the grammar.

python mysql

2022-09-21 11:08

1 Answers

As a result, you need to create a query like this.

SELECT * FROM A
WHERE (
    (column1 = 1 AND column2 = 'a') OR /* "Column2 value is a when column1 value is 1" */
    (column1 = 2 AND column2 = 'b') OR /* After that... */
    (column1 = 3 AND column2 = 'c')    /* ... You have to tie it with OR to get one of them caught. */
)

I believe that the most efficient way to do this in pymysql is to be answered by someone else, and my writing is shortened here.

Note: The query below will not work as expected. You said "where in" so just in case...

SELECT * FROM A
WHERE column1 IN (1, 2, 3)
  AND column2 IN ('a', 'b', 'c')


2022-09-21 11:08

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.