Skip to content

How to replace Over clause in sql version 4.9.5

I am trying to run a query to find the count and percentage of artisan based on gender. The query is running absolutely fine on the SQL server 8. But not on my live server which is 4.9.5. The below is my query. Answer In any database, you should be able to use:

SQL – using IF statement after WITH statement

i am making a SQl report, which uses the With statment, and with a lot of inner joins and group etc. see Working Code below. the code below does work. the problem is, this table will have output data (as a table) sometime and sometime not based on order intake. when there is not data found, i want to display

Selecting multiple rows from the same table with common column?

Have the following hypothetical table User_Mail_Info in Oracle DB Primary key is User_Id,Mail_DL,DLId. There are other columns with the table as well. How to retrieve the UserId ,given the list of (Mail_DL and DL Id) ? Note: Mail_DL and DL_Id are not directly related. This is just hypothetical data For eg. In…

How use case statement alias in where clause

I’m trying to use a case statement and the results to in an alias, but I need to use the alias in my where clause and this doesn’t seem to be working. How do I use the alias (isPrimary below) in my where clause. See comment where I’m trying to use isPrimary in my where clause, which doesn&#8…

How to sanitize Arel SQL?

I have the following Arel SQL: I get SQL Injection warning when I run brakeman. I tried the following: However, I get the following error: How do I sanitize sql statement with Arel? Answer I am answering my own question. I am using Arel following the Github wiki for Ransack gem. I was doing something very sim…