Populate todays date as column name with values derived from existing column in PostgreSQL - sql

I am trying to create a dynamic column in a table whose column name will be today's date and values will be populated based on a mathematical operation of an existing column. For example table, t1 has column a,b,c and I want to add a column called '04-26-2021' whose value will be a+b+c values. Does anyone know how we can implement it in Postgresql? Thanks

Related

I'm trying to make a generated column in one table, that contains the number of rows there are in another table

Let's say I have table A and table B. Table B needs to have a column "atr1" that counts how many rows there are in table B and also the number of columns can't exceed a constant number that's specified in another column in table B called "atr2".
I tried doing this:
alter table B
alter column atr1 type integer generated always as(count(*) from A) check (atr1 < atr2) not null;
but it gives me a syntax error at or near generated.
Generated columns can only refer to calculations on columns in the table itself. If you need to know the count from a different table, you will need to create a view instead.

Comparison of two tables based on a cross reference of columns in SQL Server

My question is about comparison of fields based on the mapping table SQL Server. In the attached image, I wanted to compare values of Table 1 and Table 2 based on the mapping provided in Table 3. For example, we need to check values of Table 1's Field 1 with Table 2's Field_3_New and other columns likewise. Mapping of these columns to compare is placed in Table 3.
I want to check, whether Table 1's Field 1 values are matching with Table 2's Field 3_NEW's values or not. We came to know that Table 1's Field 1 values have a match with Table 2's Field 3_New values based on the field mapping provided in Table 3. The above is an example scenario, I'm dealing with 40 odd fields like this.

Adding auto-incremenation on a VARCHAR column on an SQL Server table

I need to alter customer_number column in organisation table so, that it would become auto-incrementable.
As in, when adding rows to the table, this certain column would get bigger number each time. It is not the id column.
Example: If there would be no rows or only rows that have no value on customer_number column, the newly added organisation row would get 1 as the value for its customer_number column. If there would be already for example two rows with values on said column - say 100 and 200 - the new row would get value 201 on that column.
Is that even possible to do by altering an existing table and column?

How would you total the values in one column and keep a distinct value in another?

I have a database table that has multiple codes in one column that correspond to certain values in another column. For example, a particular code in column A corresponds to a value in column B. There are thousands of duplicate entries in column A that correspond to different values in column B. I want to add up all of the values in column B that have the particular code in column A, while only keeping one copy of the code from column A. You may think of the columns as key-value pairs, where column A contains the key and column B contains the value.
Basically, I want to add all the values in column B where column A is a specific value, and I want to do for this all of the unique "keys" in column A. I'm sure that this is a simple task; however, I am pretty new to SQL. Any help would be greatly appreciated.
Here is the result I'm looking for.
This should work:
SELECT
A,
SUM(B) AS sum_b
FROM [yourTable]
GROUP BY A
SELECT COLUMNA, SUM(ISNULL(COLUMNB,0)) AS TOTAL
FROM
dbo.TableName
GROUP BY COLUMNA

How to take look up values from a look up table using SSIS

I have a scenario as described below need to create a SSIS Package for that.
I have 3 COLUMNS in source table which needs to be entered in destination table.
But all these columns has to be looked up in the look up table of destination database and then enter their ID's in the destination column.
For example
Source table has 3 columns with values
idnum static type timedimension geography modified date
1 price daydate france 8/12/2015
2 RetailpRICE WEEK ITALY 9/12/2014
I want a package which looks up the column values with the matchin ID and populates in the destination table...
I know we can use the LOOKUP transform to update the data for one single column in destination table what about the other columns which I need to insert along with the lookup insertion.
How can I achieve this ? Also is there a way to pull only the recent data from the source table using modified date column values
Use a different lookup for each lookup table that you need to reference to get the Ids. So if each of your columns that you want IDs for gets its ID from a different table, then you need to use three lookups, one after the other, until you have all three IDs.