I’m trying to query in PostgresQL using the SUM function to get the total of 3 different row types (Root, Dynamic, Test). I used the Sum() function for the first attempt and the Count() function for the second attempt; both didn’t work sadly. I expect a syntax error (since I’m a beginner at …
Tag: sql
SQL request from 2 different databases with same structure
I have 2 really similar databases, with exact same structure (one of them is a backup of the other so some values changed which is why they are similar but not the exact same). So here is what I would …
App.Config in a class library for data access from WPF and ASP.NET?
I’m trying to use SQL for the first time to store data in one of my projects, I’m using this tutorial as it makes the most sense to me, and to be honest I like the guys videos, and hate clicking on hundreds of bad videos before finding one I can learn from. Anyway I’m making an app where I
Java SQL problem executing query through CallableStatement with parameter
I have a problem in a CallableStatement that execute a stored procedure query which accept a parameter. I have a list of string that contains the query like: I have a list of string that contains the parameter like I have no SQL syntax error when I run but the result set doesn’t have any value. The expe…
Condition within aggregate query vs math
I have these two query examples with small difference that i thought would be performance optimization but there is no difference. The small change is that in one of the queries there is conditional logic within the aggregate while in the other one i use simple math to get the same result. I would have though…
Reserve a range of values in a table in SQL Server
I want to reserve a range of values for the system like [1-10,000]. The user values should be inserted after 10,000. eg. There is a table that will have values inserted by the system & will also have values inserted by the user. So, when a system inserts, the id’s assigned to it will have to be betw…
Dynamic Pivot Table by Month
I’m trying to create a dynamic pivot table in SQL that will report based on month and year. I did a bunch of research and was able to come up with the below query: I am able to print the @column variable successfully, but the problems happen when I try to set it in the @dynamic variable. The error messa…
Inserting Multiple of same records into SQL temp table based on value in column
So I have table with the following records: I want to create a script to iteratively look at the Cnt_Repeat column and insert that same record in a temp table X times depending on the value in Cnt_Repeat so it would look like the following table: Answer One method supported by most databases is the use of rec…
Mysql how to select only row in same table and same identifier but different value
I have this dataset : UserPlans table : how to only select this row (with ID 3) since this data has been deleted but doesn’t have any data with deletedAt = NULL with same userId ? Answer You seem to want rows where userid has no other row whose deletedAt is null. If so, you can use not exists and
LINQ for getting the 5 latest records for each distinct name
I have been trying to get the 5 most recent records from a database with distinct names from the “Name” Column. Meaning I want the 5 latest records for each of the unique names in the table. Here is a sample table: I would expect the latest 5 Bob records (out of the 6 ), the 3 Chris records, and