說我有這個列表理解Python中請問這個Python列表讀取一個SQL查詢語句
[f(x, y) for (x, y) in itertools.product(X, Y) if g(x, y)]
其中X
和Y
是列表和f
和g
作用在列表中的成員函數。它如何轉換爲SQL查詢?這是我的解決方案:
SELECT
do_something(X.column, Y.another_column, X.our_column),
do_something_else(Y.that_column, X.that_column, Y.my_column)
FROM
this_scheme.your_table as X,
that_scheme.our_table as Y
WHERE
condition(X.column, Y.my_column) AND
another_condition(Y.another_column, X.our_column)
它是正確的嗎?可以改進嗎?它有效嗎?
效率取決於執行的細節,如索引,通常只能用於某些類型的條件(列之間的比較,而不是函數調用) – Barmar
提供了一個現實的數據樣本,預期結果 – scaisEdge
'(x,y)'意味着每個原始數據中只有一列table,'Xx'和'Yy'。這與你的SQL查詢有什麼關係,它在每個表中列出幾列?什麼是「壞」列? – Barmar