Looking for a solution In Postgresql Answer SQL has no variables, so short of using a function, you can use a common table expression: Or just:
Tag: sql
sql get balance at end of year
I have a transactions table for a single year with the amount indicating the debit transaction if the value is negative or credit transaction values are positive. Now in a given month if the number of debit records is less than 3 or if the sum of debits for a month is less than 100 then I want to charge
Override query in sql string possible? C#
Currently I’m working with my local MSSQL database and when I make a connection all works good. However that is not the question I’m having right now; I want to make my code cleaner and I don’t want to have duplicated code or almost duplicated code. For now I’m working with one large c…
Join multiple columns from the same table using Linq
I would like to convert following sql query into Linq to SQL going through this I have so far tried following which didn’t work out Edit: following query is being generated against Svyatoslav Danyliv answer which is returning 7 rows instead of 6 Answer Join which contains not just AND expressions is pos…
SQL – Select records where columns include the keyword and have the same category
I’m working on a search bar. I have two fields category and input. If the user types the query and doesn’t select a category I want to get all records matching the keyword. I’ve done it and it’s working perfectly. Now If the user select a category with the keyword. I want get records w…
Query to replace partial values in an array of int in PostgreSQL
In PotgreSQL, how do I write a query to replace some values in an int4 array? {1,2,10} -> {1,2,999} {2,3,10} -> {2,3,999} is what we are aiming for. Answer Seems like you want to replace 10 with 999, you can use array_replace
Ranking in SQL Server with a column change
Below is the original table that I want to rank according to the column changes by Install_Status and Dates for each product. Query: This SQL query returns the following results: However, I am not getting appropriate ranking for product A by date. My expected result is as below: Answer You seem to want to cou…
Using CASE with Table Join
I am using Oracle 11g. I have two tables: I want to display student_name, course, fee and a column with discounted fee where the fee is reduced by 10% if it is either ‘BIT’ or ‘MIT’. I’ve come up with following query but it gives an error: ORA-00923: FROM keyword not found where …
how to select set of records is ID is present in one of them
Here is the table where ORGID/USERID makes unique combination: I need to select all records (organizations and users) wherever USERID 1 is present. So USERID=1 is present in ORGID 1 and 2 so then select all users for these organizations including user 1 itself, i.e. Is it possible to do it with one SQL query …
Grouping the result set based on conditions
I am calculating Age of a user based on his date of birth. This gives me the UserId and his age. Now I want to group this result. How many users are in 30’s, How many users in 40’s and how many users in their 50’s.. need the count of users with their age groups If the user is >