首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在连接表的Laravel查询中使用whereDate

在连接表的Laravel查询中使用whereDate
EN

Stack Overflow用户
提问于 2021-01-26 00:17:50
回答 1查看 41关注 0票数 0

我的SQL数据库中有两个表。两者都有一个period_from列作为通用的日期格式。这两个表都有几个星期的数据,我已经连接了我的表,并且正在选择我需要的适当的列。

一切都很好,给了我正确的数据,但是一旦我添加了whereDate(),我就什么也得不到,一个空数组。我已经尝试了伪标准where(),也尝试了在我的表后面跟着我的列,例如:*.period_from,不确定为什么它在这里没有给我任何结果。

代码语言:javascript
复制
$from = Carbon::now()->subDays(14);
$to = Carbon::now();
$order = 'asc';

$data = DB::table('data_source_one as DGA')
      ->join('data_source_two as DLCA', 'DGA.created_at', '=', 'DLCA.created_at')
      ->where('event_action', 'Step 1 Loaded: (Loan Details)')
      ->select('event_count', 'sessions', 'leads', 'DGA.created_at', 'DGA.period_from', 'DGA.period_to')
      ->whereDate('DGA.period_from', '>=', $from)
      ->whereDate('DGA.period_to', '<=', $to)
      ->orderBy('DGA.created_at', $order)
      ->get();
EN

回答 1

Stack Overflow用户

发布于 2021-01-26 00:28:38

你可以这样做:

代码语言:javascript
复制
$from = Carbon::now()->subDays(14);
$to = Carbon::now();
$order = 'asc';

$data = DB::table('data_source_one as DGA')
      ->join('data_source_two as DLCA', 'DGA.created_at', '=', 'DLCA.created_at')
      ->where('event_action', 'Step 1 Loaded: (Loan Details)')
      ->select('event_count', 'sessions', 'leads', 'DGA.created_at', 'DGA.period_from', 'DGA.period_to')
      ->where('DGA.period_from', '>=', $from)
      ->where('DGA.period_to', '<=', $to)
      ->orderBy('DGA.created_at', $order)
      ->get();
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/65888510

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档