I have a table of Cases with info like the following – ID CaseName Date Occupation 11 John 2020-01-01 Joiner 12 Mark 2019-10-10 Mechanic And a table of Financial information like the following – ID CaseID Date Value 1 11 2020-01-01 1,000 2 11 2020-02-03 2,000 3 12 2019-10-10 3,000 4 12 2019-12-25 4,000 What I need to produce is
How to assign result of a sql query to a variable and use it into a built in function?
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:
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 class that holds all the methods to
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 possible via from x in entities.Where(x => ..).
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 where category is user’s selected category.
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 count the changes. For this use
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 expected: Answer You can use decode as
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 rather than SELECT *.. WHERE