说我有这个列表理解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