gpt4 book ai didi

mysql - 将 Laravel 函数翻译成 SQL 请求进行测试

转载 作者:太空宇宙 更新时间:2023-11-03 11:35:28 25 4
gpt4 key购买 nike

我想在 MySQL 中测试 Laravel 函数的输出,为此我需要将代码转换为 SQL 请求。

函数:

    return DB::table('products')
->leftJoin('product_locations', 'products.id', '=', 'product_locations.productId')
->select(DB::raw('IF(product_locations.id is not null,concat(product_locations.id,"-","M"),concat(products.id,"-","N")) as id'), DB::raw('IF(product_locations.id is not null,1,0) as multilocation'), 'products.productName', 'products.productName as text', 'product_locations.productLocationName', 'product_locations.binLocationName', 'product_locations.unitCost', 'product_locations.amount')
->orderBy('products.productName')
->distinct()
->get();

最佳答案

使用查询日志:

DB::connection()->enableQueryLog();

DB::table('products')
->leftJoin('product_locations', 'products.id', '=', 'product_locations.productId')
->select(DB::raw('IF(product_locations.id is not null,concat(product_locations.id,"-","M"),concat(products.id,"-","N")) as id'), DB::raw('IF(product_locations.id is not null,1,0) as multilocation'), 'products.productName', 'products.productName as text', 'product_locations.productLocationName', 'product_locations.binLocationName', 'product_locations.unitCost', 'product_locations.amount')
->orderBy('products.productName')
->distinct()
->get();

dd(DB::getQueryLog())

关于mysql - 将 Laravel 函数翻译成 SQL 请求进行测试,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46390589/

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