I am using this query. select * from customers E JOIN `customer_p` D ON (E.ID = D.`P_ID`) Here E.ID is primary key of customers table and p_ID is foreign key of customer_p This query fetches only …
Copy data from one row to another in SQL Server in the same table
I have a table that has two variations of data: Table MYDATA I would like to update Version A’s StreetNumber into Version B. There will be thousands of records and the match will be on the Address column I thought to use: But it seems the nesting is not looking at the row to be updated…rather its …
tSQLt apply NOT NULL constraint
How do I apply the NOT NULL constraint back onto a column of a table in tSQLt? CREATE OR ALTER PROCEDURE [test abc].[test abc1] AS BEGIN — Arrange EXEC tSQLt.FakeTable ‘dbo’, ‘table1’; –…
How to find the average distance between the locations
I have a table with source, destination and distance between the locations like as below i want to calculate average distance between the locations like, for example if we take A to B route 1: 21 miles, route 2: 28 miles, route 3: 19 miles I am expecting results: A to B –> 22.66 miles Thanks Answer B…
Using ISNULL or COALESCE on date column
I’ve got a date column where some rows have got NULL values. I would like to use ISNULL or something like that to substitute those values with something like ‘N/A’, however, when I try to use ISNULL, I get an error due to two different data types. If I try to convert my Date column to VARCHAR in order to…
Coalesce of multiple values group by date in postgres
I have a table as shown below: I need to select columns based on identity_no and also, need to select non zero/non null column values grouped by src_date. so when I query on the identity_no, I want …
How to aggregate values in rows based on condition and getting output in sql?
My table contains few rows, which has to be aggregated. eg: Columns are sites, fuel, sales, date when date ,sites and fuel is same I need to aggregate the sales column for those rows and have one row….
BigQuery query on (custom) timestamp partitioned table returns zero results
I have a table in a dataset with the following schema: date TIMESTAMP id INTEGER … The table is partitioned on the date column. Displaying a preview of the table in the BQ UI reveals it has many …
MySQL select a certain amout of rows for each type in a certain c
I would like to select the first certain number of rows, by groups of a certain column. For example : Original data: index type value 0 1 a 0.716430 1 2 a 0.223650 2 …
SQL : calculate multiple rows to result
How to get result table by calculate multirow? Name Type Value —————————— Name1 Plus 5000 Name1 Minus 1000 Name2 Plus 3000 Name2 Minus 2000 …