I am getting the following data: and I want to get the data before the -. For 42ND-1000 I want 42ND only. Answer This is basic string manipulation. In SQL Server, you would do:
Avoid N+1 query in large data set
I have a migration which updates existing records with a new attribute value. The model is called ‘MyRecord’. It has millions of records in the database with a new unit_id column of null. I want to …
Where clause only return one condition instead two using OR
I have a simple select statement like: SELECT * FROM [customer] AS [c] INNER JOIN [customertype] AS [ct] ON [c].[CustTypeKey] = [ct].[CustTypeKey] INNER JOIN [ProjectCustomer] AS [pc] ON [c].[…
SQL Continuous Date Ranges Previously Grouped Data
I’m working with a data extract that represents claims data for a population. The ultimate goal is to be able to associate specific claims to unique encounters. The way we’d define an encounter is a …
cannot drop a foreign key in mySQL
It’s a common example between Persons and Orders. I just copied it from Internet as a test. CREATE TABLE Persons ( ID int NOT NULL, LastName varchar(255) NOT NULL, FirstName varchar(…
Select all entries from a table which are older then 3 days
I’ve this table in my database: ————————————————- | id | name | model | inserted_time (timestamp) | ———————————————…
Complicated logic of group by and partition
I have the table as per the script below. The data that I want finally is shown in the screenshot. The logic that is to be implemented is : If SUM(FPR_QTY) > QPA, Use QPA without summing it up. Else, …
Meeting 2 conditions in 2 different columns
I’m trying to run a query where I need very specific conditions to be met: Sales code is All Item has Original Price flag set Item has a price with no Original Price flag set that is the same as the …
Find authors who ONLY wrote history books
New to SQL, although catching on – stuck on this query. This works, although Paddy O’Furniture should not be showing up as this author hasn’t written any book and his au_id does not appear in the …
postgresql inner join and left join
I have the following database structure, with postgres 9.5: create table users ( id character varying(255), email character varying(127) ); create table org_users( id character varying(255), …