开发者

What am I doing wrong? Min(date), group by user

开发者 https://www.devze.com 2023-03-15 06:55 出处:网络
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 fo
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 st开发者_如何学JAVAart_date as well: from_days(min(to_days(date(tx_date))))


I think the logic in your query is fine. Does you table my_table has an id column that is a primary key? The problem might be that the query is grouping by the id column of your table rather than id alias that you have used in your query.

Try this if its account_id you want to GROUP on:

SELECT min(date(`tx_date`)) as start_date, `account_id` as 'id'
FROM my_table
group by `account_id`;

I think your query has 2 extra closing braces around min(date(tx_date)) and should be causing errors.

0

精彩评论

暂无评论...
验证码 换一张
取 消