php - 具有多个连接的重复行
问题描述
我正在使用此代码在内容表上加入两个表,然后在我仅加入分析表时按用户分组,结果也是正确的
->where('users.type_id', 2)
->leftJoin('contents', 'users.id', '=', 'contents.instructor_id')
->leftJoin('analytics', 'contents.id', '=', 'analytics.content_id')
->leftJoin('reactions', 'contents.id', '=', 'reactions.content_id')
->selectRaw('
users.id as id,
concat(users.name, "-", users.last_name) as name,
sum(analytics.total_watched) as sum_watched,
count(analytics.id) as times_watched,
sum(analytics.completed=1) as completed_video,
sum(reactions.reaction_type="love") as love,
sum(reactions.reaction_type="happy") as happy,
sum(reactions.reaction_type="thinking") as thinking,
sum(reactions.reaction_type="sad") as sad,
sum(reactions.reaction_type="angry") as angry
')
->groupBy('users.id')
->limit(10)
->get();
解决方案
推荐阅读
- powershell - 从 powershell 运行 cosmosdb 命令
- javascript - javascript作为关键字,导入中“as”后的多个名称
- python-3.x - 将字符串更改为字节,但格式为字符串
- html - 使用 XPath 表达式从 HTML span 元素中提取全文
- gatsby - Gatsby 自动链接标头不生成锚链接
- python - Discord.py bot 未与 firebase 实时数据库连接
- java - 将 Firebase 图像作为可绘制对象检索并显示在回收站视图中
- r - 提高 RStudio 图形设备的质量(预览)
- javascript - 使用 React 向 Binance API 发出 GET 请求时遇到问题
- python - Python:根据条件拆分单列