这是我的mysql查询:
SELECT product_tasks.id AS product_task_id,
tasks.id AS tasks_id,
tasks.task_name AS label,
tasks.serial_id AS serial_id,
(SELECT serials.starting_series
FROM serials
WHERE serials.id = serial_id) AS starting_series
FROM product_tasks
JOIN tasks ON tasks.id = product_tasks.task_id
WHERE product_tasks.product_id = 1;
这是我雄辩的问题,但我还没说完:
ProductTask::select('product_tasks.id as product_task_id',
'tasks.id as tasks_id', 'tasks.task_name as label',
'tasks.serial_id as serial_id', * INSERT missing query here *)
->JOIN('tasks', 'tasks.id', 'product_tasks.task_id')
->WHERE('product_tasks.product_id', 1)
->get();
我雄辩的提问中遗漏了什么?
3条答案
按热度按时间mhd8tkvw1#
你能用下面的格式创建子查询吗
z6psavjg2#
试试这个雄辩的问题:
vptzau2j3#
使用
DB:raw()
```ProductTask::select(
'product_tasks.id as product_task_id',
'tasks.id as tasks_id',
'tasks.task_name as label',
'tasks.serial_id as serial_id',
DB::raw("SELECT serials.starting_series as starting_series FROM serials WHERE serials.id = serial_id"))
->join('tasks', 'tasks.id', 'product_tasks.task_id')
->where('product_tasks.product_id', 1)
->get();