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

Sum if query #5

Open
bigbentobox opened this issue Mar 12, 2013 · 1 comment
Open

Sum if query #5

bigbentobox opened this issue Mar 12, 2013 · 1 comment

Comments

@bigbentobox
Copy link

Is it posisble to a make a query that do a sum with if inside?

For example :

SUM(if( users.origin IS NULL, 1,0))

Checked the documentation but don't find the if statement, there is a workaround?

@asterite
Copy link
Owner

Hello,

Could you show me the full query you want to perform, including the model you are querying against?

You could use a virtual column: https://github.com/asterite/rgviz-rails#virtual-columns

So you would do:

render :rgviz => User, :virtual_columns => {
    'user_origin_is_null' => {
        :sql => "case when users.origin is null then 1 else 0 end",
        :type => :string
    }
}

I'm not sure you can do "if" in SQL (in GQL I know you can't)

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