我正在做一個簡單join的查詢job_roles和operations表。fk是對 的列job_role_id的operations參考id列job_roles。
我需要的輸出是從不等于的operations地方獲取資料的總數operations.structure_costjob_roles.cost_type
我MySQL Workbench使用以下代碼創建了一個作業查詢:
SELECT COUNT(*) as total
FROM
job_roles t1
RIGHT JOIN
operations t2 ON t2.job_role_id = t1.id
WHERE
t2.structure_cost != t1.cost_type
t2.master_id = 1; ### get operations only for auth user
以下是我的查詢Laravel不起作用。Count我在下面的資料示例中得到的3是wrong,Count 應該回傳1,如where clause

表名:job_roles

表名:操作

uj5u.com熱心網友回復:
函式的第三個引數where用作值而不是列名。使用whereRaw功能
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/529571.html
標籤:mysql拉拉维尔
上一篇:更改表外鍵
