I am looking for a query that selects a record from each group that meets a user-defined criterion. I can explain with the following illustrative table: A simple GROUP BY categoryID query returns the first record in each group, as shown below: To return the last record in each group we can use the approach su…
Tag: sql
Get the Defect Type with the maximum Total Defect Qty
I have the following query which gets the sum of defect quantity per Defect Type : SELECT [Defect Type] ,YEAR([Date]) AS YearOfDefect ,SUM([Total Defect Qty]) AS [Sum] FROM SupplierQuality GROUP BY […
I want to update my table columns based on another one
I have one database that I’ve created a year ago but then I’ve created a new one recently and added some new columns into tables. I want to update my ex database with new schema without losing my data….
Compilation throws `None of the following functions can be called with the arguments supplied`
Trying to implement a custom JSONB binding that maps to an object containing a map. Generated code throws a None of the following functions can be called with the arguments supplied error caused by the following line: Here’s my configuration: Also, it seems like the line causing problems is mapping data…
How to pass a seed value to random order function in Sequelize
In SQL dialects you can sort by random and you can pass a seed to the random function in order to get a repeatable random order of rows. In MySQL you’d do it like this: SELECT * FROM `users` ORDER BY …
SQL: Change the value of a column in function of another
I get a table from SQL that I put whitin a winform’s datagridview. I just want to change the value of my last column in funtion of another. Here is the example: I have 4 columns : ID / Price / …
SQL Query count with group by and having at least one date filled
I need to write a sql query where I count number of employees who are not featured. Each employee can have multiple records with member comments. If they are featured then the feature date will have …
Limited By Value Postgresql query
I have a couple of rows where values in one column are repeating and I need to get a couple of rows where every value is limited by const. For example, i have this rows (1, ‘a’) (2, ‘b’) (3, ‘a’) (4,’…
Eliminate duplication from a SQL query to avoid returning NULLs from a LEFT/RIGHT JOIN
Have this MS SQL query SELECT COUNT(*) AS Total, CASE WHEN COUNT(*) = 0 THEN 0 ELSE SUM(ISNULL(p.AmountGB, 0)) END AS AmountGB, CASE WHEN COUNT(*) = 0 THEN 0 ELSE SUM(ISNULL(p.TaxAmountGB, 0)) END AS …
How to fix my postgres function syntax to fit a user parameter
I’m trying to make a postgreql function, I’m a little confused on which syntax format to use when I’m passing a select statement that takes in a parameter (this parameter can be a string or a list of …