Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 5 months ago.
Improve this question
I need to do an union between 2 tables and there is a column on the first table that doesn't exist on the second table, so, I would like to set up a column with null's (e.g: select null as column_name from table2). However, it involves a SUM and I can't use "null as Sum(column_name)" since it doesn't work. Since the values are null, the sum would be 0.
So, how do I select a sum from a column that doesn't exist in a table but I will insert null values on that column?
In your union, when you select from the table that does not have the column in question, just include null as <column name> in the appropriate position in your select statement. Or you could do 0 as <column name>, whatever works better for you.
You could apply ZEROIFNULL around that column to make them 0.
SUM(ZEROIFNULL(UnionColumn)) This should work fine with Teradata.
Related
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 3 years ago.
Improve this question
i have only one row with a lot columns in my table. I want to select columns with values greater than zero.
WHERE (col_1 > 0) and ... (col_99 > 0)
It will be too long query, if i want to write all statements. Does it possible to write query with selecting columns with values > 0 ?
Bro flow the method its lengthy by works.
First you unpivot the data and select values where column value > 0
secondly Pivot again and you will get you desire result.
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 7 years ago.
Improve this question
I have the one table eg tbl_1 and i have column eg A B C. When I insert into column A and B its result store into C like c=a-b.
If you wish to create virtual/computed columns while creating a table structure, Since you dint specified which RDBMS you are using, please following links (the one that suits you) :
Hope it helps you.
MYSQL
ORACLE 11G
SQL SERVER
CREATE TABLE tbl_1
(
A int,
B int,
C AS A - B
);
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 7 years ago.
Improve this question
i got this table, and i want to divide all the values on one of the columns except one.
I havent wrote any code about it just looking for an explanation on how to do it, if anyone could help out would appreciate.
In order to modify the content of one column in all rows except one, you can use the following query:
UPDATE tablename SET columName = columnName / 42 WHERE rowId !=42;
WHERE contains the condition that has to evaluate to true, in order for the update to take effect. My example modifies all rows except for those whose rowId column contains the value 42.
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
I have two tables, one big and one small. Both contain columns ID and EffectiveDate.
The bigger table has more other columns and of course more rows than the smaller table.
Under the condition that ID for both tables are the same, the EffectiveDate column is earlier in the small table than the big table. I want to replace the EffectiveDate in the big table by the value of the EffectiveDate column from the small table.
What should I do?
Seems like a very basic SQL query....
UPDATE bt
SET EffectiveDate = st.EffectiveDate
FROM dbo.BiggerTable bt
INNER JOIN dbo.SmallerTable st ON bt.ID = st.ID
-- maybe you also need this condition, if not *ALL* EffectiveDate values in the
-- smaller table are indeed before the values in the bigger table
WHERE st.EffectiveDate < bt.EffectiveDate
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 9 years ago.
Improve this question
I have two tables in my sqlite database, with a column name as in both tables solution, solutionimage, id saying tableA and tableB. I want to, copy from tableB solution, solutionimage to tableA matching the id in both table respectively, how to do it?
I have google it and tried but i didnt get it.. Any one help me. Thanks a lot in advance.
Ideally you would want to join the table you are updating to the other table where you take the values from.
But I just read that JOINS in UPDATES are not allowed in SQLITE so subqueries are the way to go I suppose:
UPDATE tableB
SET
Solution = (SELECT Solution FROM tableA WHERE ID = tableB.ID),
SolutionImage = (SELECT Solution FROM tableA WHERE ID = tableB.ID);
See this fiddle for example output.