I have a nvarchar column with dates formatted like this: “04/18/2021 13:04:15” (without quotes). I want to change this column to be datetime and migrate all of it data. I’ve looked for format codes and figured out, that closest code to my variant is U.S (101). So I tried to But I get error: …
SQL Trigger with loop from another table
I’ve got 2 tables : Table A Table B The table A contains the following values : The Table B contains the following values : My goal is to set the column B.chk with the number of occurence from table A when a new row is created on table B. For example : The trigger on table B should set
Store Pricing Combinations and Sums w/ SQL
I have a table that looks something like and I would like to create all possible combinations with the sum of the prices, including the unique values to create something like what would be the quick and dirtiest way of accomplishing this? Answer Use three joins:
Count from 4 tables with join and null values
Tables: What I am expecting to query is this: However this is what I get: With this query: I wonder, in what way the query above could be modified to return the expected results? What would be a good approach to achieve this? Answer You are joining along two dimensions, so you are getting a Cartesian products…
SQL for identifying % of orders placed within 20 minutes of each other
Have a dataset like below and would like to know various ways to solve the question of : what % of orders were within 20 minutes of each other? CustomerId Order_# Order_Date 123 000112 12/25/2011 10:30 123 000113 12/25/2011 10:35 123 000114 12/25/2011 10:45 123 000115 12/25/2011 10:55 456 000113 12/25/2011 10…
SQL query Postgres 12
I’m doing an inner join on a table like this: The condition f.vac_1 = mv.id might not been satisfied in the case where a person have not been vaccinated. In such case, I don’t want to ignore the row, but instead of displaying the vaccine name (which is the purpose of the inner join) to display an …
What is wrong with my stored procedure SQL query on PostgreSQL?
I tried many times with or without the semicolon but still shows me the error message. ERROR: syntax error at or near “INSERT” LINE 13: INSERT INTO Advertisement(ad_id, business_id, requested_on… ^ SQL state: 42601 Character: 712 I am sure the table constraint and sequence are all correct bu…
SQL select query retrieval blank return
I have to retrieve distinct entities from a column, all of which start with a vowel. The query looks like this : It’s not giving compilation errors, but it’s not returning anything. Any ideas? Answer You can use regular expressions: LIKE wildcard patterns do not support character classes, except i…
How to use two where conditions in SQL?
Following is the query I have written and I need to where conditions. Admin_Level_3_palika is not null Year = ‘2021’ However, the following query is still giving me null values for Admin_Level_3_palika Please help me with how to work with this. Following is an example of my dataset, Epid_ID being …
SQL subqueries PostgreSQL 12
I’m having a table similar to this: first last date pos john doe 18-03-2021 harris potter 10-06-2021 john doe 10-05-2021 harris potter 14-06-2021 jessica potter 14-06-2021 kermit foster The use case is as follow: The pos column correspond to a positive covid test The date column correspond to the vaccin…