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

SELECT DISTINCT ON COLUMN #113

Closed
DevX86 opened this issue Jan 1, 2022 · 3 comments
Closed

SELECT DISTINCT ON COLUMN #113

DevX86 opened this issue Jan 1, 2022 · 3 comments

Comments

@DevX86
Copy link

DevX86 commented Jan 1, 2022

Attempting to-do a

SELECT 
    COUNT(DISTINCT column_name),
    another_column,
    another_column
...

Is this currently possible @go-jet ? I saw SELECT(table.Table.ColumnName)).DISTINCT() But that wouldn't work in this scenario.

@go-jet
Copy link
Owner

go-jet commented Jan 1, 2022

Currently, this is only possible with raw expressions:

s := SELECT(
	Raw("COUNT(DISTINCT(table.column))")).AS("alias")
FROM(table)

@go-jet go-jet added this to the Version 2.7.0 milestone Jan 1, 2022
@DevX86
Copy link
Author

DevX86 commented Jan 1, 2022

Seems to work, that's a pretty cool way to implement things until we have it typed as we don't have to make the entire statement raw, just the part that's unique.

@go-jet go-jet mentioned this issue Jan 20, 2022
@go-jet
Copy link
Owner

go-jet commented Jan 20, 2022

Aggregate DISTINCT operator included in Release 2.7.0.
Sample usage:

stmt := SELECT(
Payment.CustomerID,
COUNT(DISTINCT(Payment.Amount)).AS("distinct.count"),
SUM(DISTINCT(Payment.Amount)).AS("distinct.sum"),
AVG(DISTINCT(Payment.Amount)).AS("distinct.avg"),
MIN(DISTINCT(Payment.PaymentDate)).AS("distinct.first_payment_date"),
MAX(DISTINCT(Payment.PaymentDate)).AS("distinct.last_payment_date"),
).FROM(

@go-jet go-jet closed this as completed Jan 20, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants