【问题标题】:How can I make this query in Laravel:如何在 Laravel 中进行此查询:
【发布时间】:2020-01-10 05:47:48
【问题描述】:
SELECT * 
FROM time_table_rup t 
INNER JOIN gruppa g ON t.group_id = g.gruppa_id 
INNER JOIN discipline d ON t.discipline_id=d.discipline_id 
WHERE sikl = 5 AND t.semestr % 2 = 1

【问题讨论】:

  • 您想要原始查询,还是已经为这些表定义了模型和关系?
  • 你尝试了什么?
  • Ahmed Shefeer 我为这些表定义了模型和关系
  • 那么你的问题是如何从 laravel 对 mysql 数据库执行查询?

标签: mysql laravel


【解决方案1】:

像这样使用查询生成器:

DB::table('time_table_rup AS t')
->join('gruppa AS g', 't.group_id', '=', 'g.gruppa_id')
->join('discipline AS d', 't.discipline_id', '=', 'd.discipline_id')
->where('sikl', 5)
->where(DB::raw('t.semestr % 2'),1)
->get()

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-05-30
    • 2020-05-21
    • 2010-10-07
    • 2010-10-13
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多