gpt4 book ai didi

sql - 将连接转换为 SQL 中的子查询(laravel Controller )

转载 作者:行者123 更新时间:2023-12-04 21:51:28 25 4
gpt4 key购买 nike

我有两个以上的表,同时从数据库中获取 2,00,000 记录花费了我预期的太多时间,因此我需要将其转换为子查询吗?

以下代码:

->join('track_details','track_details.code','=',$esealTable.'.primary_id')
->join('track_history as th','th.track_id','=','track_details.track_id')
->join('locations as l','l.location_id','=','th.src_loc_id')
->join('products','products.product_id','=',$esealTable.'.pid')
->where(['level_id'=>0, 'products.product_type_id'=>8003])
->whereIn('l.location_type_id',[741,744])
->whereIn('th.transition_id',[537,569]);
->get(['primary_id as iot','products.material_code','th.sync_time as datetime'])
->take(200000);

最佳答案

如果您需要使用 json 中的 query 检索所有这些 data

Laravel 提供了类似于toArray() 函数的toJson() 函数。请参阅文档 here .您只需要在查询末尾添加 toJson(),如下所示:

->join('track_details','track_details.code','=',$esealTable.'.primary_id')
...
...
..
->get(['primary_id as iot','products.material_code','th.sync_time as datetime'])
->take(200000)
->toJson();

这样就可以直接将抓取到的数据转为json格式。

关于sql - 将连接转换为 SQL 中的子查询(laravel Controller ),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44878353/

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