Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

I want to use DISTINCT COUNT in rel.Select, how can I do that? #329

Closed
hxgdzyuyi opened this issue Apr 25, 2023 · 2 comments
Closed

I want to use DISTINCT COUNT in rel.Select, how can I do that? #329

hxgdzyuyi opened this issue Apr 25, 2023 · 2 comments

Comments

@hxgdzyuyi
Copy link

	type UvDictRow struct {
		Adid      string
		AdidCount int
	}
	var uvDictRows []UvDictRow
	err = repo.FindAll(
		ctx,
		&uvDictRows,
		rel.Select("adid", "COUNT(DISTINCT userid) as adid_count"),
		rel.From("log_visits").Group("adid"),
		where.Eq("plan_id", plan_id),
	)
	if err != nil {
		return
	}

*mysql.MySQLError=Error 1054: Unknown column 'log_visits.DISTINCT userid' in 'field list', string=args, []interface {}=[[26]])
{"error": "Error 1054: Unknown column 'log_visits.DISTINCT userid' in 'field list'"}

@Fs02
Copy link
Member

Fs02 commented Apr 25, 2023

seems this is no documented yet, but you can avoid escaping the field by using ^ prefix, example:

rel.Select("adid", "^COUNT(DISTINCT userid) as adid_count"),

@hxgdzyuyi
Copy link
Author

thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants