dpd3447 2018-08-17 04:59
浏览 40
已采纳

从两个表中获取唯一结果或如何通过ID在laravel中减少两个表

I have Two Tables Fee and Bill_Fee . Bill_Fee has been made to resolve the many to many relationship between Fee and Bill.

Fee
----------
id    
amt  
student_id

Bill_Fee
----------
fee_id   
bill_id

First the Fee table should be selected with the help of student_id and then i need to MINUS as a set(A={1,2,4,6,8} B={1,2,6,8,9,0}) A-B={4} Like this so that if the fee_id exists in bill fee the details of those fees should not be extracted. and Those fee_id which are not in Bill should be extracted

  • 写回答

1条回答 默认 最新

  • du8794 2018-08-17 05:11
    关注

    you can use sub query & NOT EXISTS like this

    SELECT *
    FROM Fee AS a
    WHERE NOT EXISTS (
      SELECT *
      FROM Bill_Fee AS b 
      WHERE a.id=b.fee_id
    )
    

    there is multiple way to execute query in laravel

    you can execute query like this

    $sqlQuery = "SELECT ____________";
    $result = DB::select(DB::raw($sqlQuery));
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 Oracle中如何从clob类型截取特定字符串后面的字符
  • ¥15 想通过pywinauto自动电机应用程序按钮,但是找不到应用程序按钮信息
  • ¥15 如何在炒股软件中,爬到我想看的日k线
  • ¥15 seatunnel 怎么配置Elasticsearch
  • ¥15 PSCAD安装问题 ERROR: Visual Studio 2013, 2015, 2017 or 2019 is not found in the system.
  • ¥15 (标签-MATLAB|关键词-多址)
  • ¥15 关于#MATLAB#的问题,如何解决?(相关搜索:信噪比,系统容量)
  • ¥500 52810做蓝牙接受端
  • ¥15 基于PLC的三轴机械手程序
  • ¥15 多址通信方式的抗噪声性能和系统容量对比