The following query: Returns the following sample data: Where on the first of the month, Confirmed = Y, I need to return the Declared column for that month. Note, Confirmed = Y will only exist on the first of the month. That column is blank in all other cases Otherwise, I need to return each Interim column fo…
Tag: sql
sql nested “sum (case when) or” select query
I have a select query where I am trying to sum a value based on multiple criteria, grouped by dimension. The output will be the sum of the time greater than 30, 90, or 365 days based on the category, grouped by category. I can’t crack the syntax for this, I hope you can help! The concept looks something…
How do I count the customers that made more than a purchase?
I have a table called order that looks like this: I am trying to display: 1.Total count of customers that bought 1 time only (that went to the store in one occasion, it could have been that they bought multiple items but it is only a one time event) 2.Total count customers that bought more than 1 time (that w…
How Select record with where clause with math using ActiveRecord?
I want to return a list of records whose created_at more than 5 seconds before its updated_at i.e. But this syntax doesn’t appear to work. Getting the error: Answer You didn’t say what database you are using, but with MySQL you can the TIMEDIFF function for this: If you are using Postgres:
How to get student attendance_status by date using sql query?
In my database I have this data. Now I want to query and fetch data based on date and group by roll_number. I am able to fetch all the data using But I am not able to find what I want. I am learning databases and SQL. I used group by option like below but my result is not what
SQLite: Selecting multiple counts from one column
I am running a query with SQLite and am relatively new to this. Glance of my dataset: I want group the results by Col A and then show 3 more columns (mild, moderate, high) and their counts — Here is what I’m looking for: I know how I can select just one of the columns (say, mild), but not sure
MySQL Group by with named columns from grouped data
I’m writing an application to record 10 pin bowling game results. I’ve done the submission bit but I’m stuck on displaying the results. Here is the structure: In the example above I am assuming each person played 3 games, however any number of games could be played. How can I get the data in…
Difference between x = null vs. x IS NULL
In Snowflake, what is the difference between x = NULL and x IS NULL in a condition expression? It seems empirically that x IS NULL is what I want when I want to find rows where some column is blank. I ask because x = NULL is treated as valid syntax and I am curious whether there’s a different applicatio…
Have multiple parameters in a WHEN part of a SQL Update Statement
I need to write a sql update statement without repeating the parameter on the WHEN part of the query, below query works fine however I would like to group the related parameters together, this is how the current query looks like for example I would like to use an IN to group bundle all the STCs belong to 40 t…
Group by issues with multiple columns
I am having trouble making a query work. I am selecting 5 columns, using 3 to filter and 1 to count: I keep getting an error that the other columns have to be grouped by or aggregated. I’m trying to get the total students per class per professor. I’m only selecting the other columns so I can filte…