我做错了什么?分钟(日期),按用户分组
SELECT min(date(`tx_date`)))) as start_date,
`account_id` as 'id'
FROM my_table
group by id
这将返回每个 tx_date,而不是分组并为我提供每个用户的最小值。我也对 start_date
尝试过:from_days(min(to_days(date(tx_date))))
SELECT min(date(`tx_date`)))) as start_date,
`account_id` as 'id'
FROM my_table
group by id
This is returning each tx_date
and not grouping and giving me the min for each user. I've tried this for start_date
as well: from_days(min(to_days(date(tx_date))))
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我认为你的查询逻辑很好。您的表
my_table
是否有一个作为主键的id
列?问题可能是查询是按表的id
列而不是您在查询中使用的id
别名进行分组。如果您想要对其
account_id
进行分组,请尝试此操作:我认为您的查询在 min(date(
tx_date
)) 周围有 2 个额外的右大括号,并且应该会导致错误。I think the logic in your query is fine. Does you table
my_table
has anid
column that is a primary key? The problem might be that the query is grouping by theid
column of your table rather thanid
alias that you have used in your query.Try this if its
account_id
you want to GROUP on:I think your query has 2 extra closing braces around min(date(
tx_date
)) and should be causing errors.