sql - 如何从 Laravel 中的日期按月份搜索
问题描述
我正在尝试这样:
$cost=DB::table('breakfast_orders')
->join('breakfast_costs','breakfast_orders.date','=','breakfast_costs.date')
->where('breakfast_orders.user_id',1)
->WHERE(' MONTHNAME(date)='June'')
->sum('breakfast_costs.total_cost');
或者以下 sql 的转换可能对我有帮助:
SELECT * FROM `breakfast_orders` WHERE MONTHNAME(date)='June'
解决方案
$month = 'June';
$cost=DB::table('breakfast_orders')
->join('breakfast_costs','breakfast_orders.date','=','breakfast_costs.date')
->where('breakfast_orders.user_id',1)
->whereRaw('MONTH(date) = '.$month)
->sum('breakfast_costs.total_cost');
推荐阅读
- c# - ClosedXML 数据透视表集计算
- spring - 在超类上使用 @Id 时得到“org.hibernate.AnnotationException:没有为子实体指定标识符:”
- relationship - 有没有办法从 'GloVe' word2vec 获得关系?
- protocol-buffers - 如何分隔一系列协议缓冲区消息,以便可以向后和向前读取它们?
- intellij-idea - IntelliJ IDEA:如何禁用临时运行/调试配置创建或保留永久配置?
- python - python27发布请求失败
- java - 线程“主”java.lang.NoSuchMethodError 中的 Spring 异常:org.springframework.util.ReflectionUtils.clearCache()V
- xpath - 如何使用具有 2 X 2 种结构的 xpath 选择元素?
- amazon-web-services - 无法从 S3 存储桶(镶木地板文件)将数据加载到 EMR 上的猪中
- python - pyinstaller 缺少 mxnet dll