mysql - 将不同的列分组为一行
问题描述
如何在不同的行和列中制作一行
SELECT
internal_id, store_id, user_id, shift_info,
DATE(log_datetime) dates,
(case when log_action = '0' then TIME(log_datetime) end) as time_in,
(case when log_action = '0' then CONCAT(log_lat, ",", log_lng) end) as loc_in,
(case when log_action = '1' then TIME(log_datetime) end) as time_out,
(case when log_action = '1' then CONCAT(log_lat, ",", log_lng) end) as loc_out
FROM
attendance_store_user
WHERE
user_id = "A4CBD64F-D21C-5612-CCF5-497892B62E76"
我想要这样的结果:
解决方案
您可以尝试对空 time_out 和 time_in 使用同一个表过滤器的连接
select a.dates, a.store_id, a,time_in, b.time_out
FROM attendance_store_user a
INNER JOIN attendance_store_user b on a.dates = b.dates
and a.user_id = b.user_id
and a.time_out is null
and b.time_in is null
WHERE a.user_id = "A4CBD64F-D21C-5612-CCF5-497892B62E76"
推荐阅读
- angular - Angular 验证器生产
- php - 无法在我刚刚安装的 php 中使用 Archive_Zip
- hibernate - JPA:循环关系:EclipseLink 和 Hiberante 之间的差异
- python - Windows 10上的Tensorflow安装问题
- laravel - Laravel 表单输入多选
- java - 使用 JDBC 连接到 Athena 时找不到合适的驱动程序
- python - FastAPI - HTTP 基本身份验证 - 选择自己的用户名/密码和 Base64
- reactjs - 在 React 中将错误的类型数据传递给组件的属性?
- python - WheelCommand 至少需要 3 个参数,但只给出 2 个
- php - 通过蓝图数组映射列表动态地 json 对象返回数组 1 维