gpt4 book ai didi

MYSQL 到 CakePHP

转载 作者:行者123 更新时间:2023-11-30 00:25:29 25 4
gpt4 key购买 nike

我想将以下复杂的mysql转换为cake的find表达式:

SELECT p1, p2
FROM
(
SELECT IFNULL(a.c2, '10') AS p1, IFNULL((SELECT MAX(c.c1) FROM my_table c WHERE c.c1>p1), '30') AS p2
FROM my_table a
WHERE
(
(a.user_id = 2) AND (a.c1 BETWEEN '10' AND '30')
)

) as temp
WHERE p2 > 100
ORDER BY p1;

我尝试遵循 http://dogmatic69.com/sql-to-cakephp-find-converter但无法生成所需的表达式。

请帮忙。我真的不知道如何处理如此复杂的表达式(我不喜欢在cakephp中使用查询)

谢谢

最佳答案

让我将您的查询转换为 cakephp 方式如果表a的模型是A:

$fields = "IFNULL(A.c2, '10') AS p1, IFNULL((SELECT MAX(C.c1) FROM my_table c WHERE C.c1>p1), '30')    AS p2";
$conditions = "A.user_id=2 AND A.c1 BETWEEN '10' AND '30'";
$inner_querry = $this->A->find("all", compact("fields", "conditions"));

$fields = "p1,p2";
$conditions = "p1 IN ($inner_querry) AND p2 IN($inner_query) AND p2 > 100";
$order = "p1";
$query = $this->A->find("all", compact("fields", "conditions", "order"));

debug($query); //check results of for error.

关于MYSQL 到 CakePHP,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22927234/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com