Total Sum of two columns and show in the third ColumnAdd a column with a default value to an existing table in SQL ServerSQLite - UPSERT *not* INSERT or REPLACESELECT DISTINCT on one columnSQL update query using joinsHow can I get column names from a table in SQL Server?SQL Server: How to Join to first rowWhat are the options for storing hierarchical data in a relational database?SQL select only rows with max value on a columnReset identity seed after deleting records in SQL ServerHow to sum two column & save in database
What does this 7 mean above the f flat
Go Pregnant or Go Home
Is this Spell Mimic feat balanced?
Modify casing of marked letters
Are there any comparative studies done between Ashtavakra Gita and Buddhim?
How was Earth single-handedly capable of creating 3 of the 4 gods of chaos?
Increase performance creating Mandelbrot set in python
Generic lambda vs generic function give different behaviour
Tiptoe or tiphoof? Adjusting words to better fit fantasy races
What to do with wrong results in talks?
What is the oldest known work of fiction?
Is there a good way to store credentials outside of a password manager?
apt-get update is failing in debian
Can I use my Chinese passport to enter China after I acquired another citizenship?
Is there any reason not to eat food that's been dropped on the surface of the moon?
Coordinate position not precise
Should my PhD thesis be submitted under my legal name?
What is difference between behavior and behaviour
Why are on-board computers allowed to change controls without notifying the pilots?
Is a roofing delivery truck likely to crack my driveway slab?
Student evaluations of teaching assistants
Is exact Kanji stroke length important?
voltage of sounds of mp3files
Why did Kant, Hegel, and Adorno leave some words and phrases in the Greek alphabet?
Total Sum of two columns and show in the third Column
Add a column with a default value to an existing table in SQL ServerSQLite - UPSERT *not* INSERT or REPLACESELECT DISTINCT on one columnSQL update query using joinsHow can I get column names from a table in SQL Server?SQL Server: How to Join to first rowWhat are the options for storing hierarchical data in a relational database?SQL select only rows with max value on a columnReset identity seed after deleting records in SQL ServerHow to sum two column & save in database
I have a Three columns in the SQL table,
I want to show the sum of the total of two columns in the third column. How can I show that using SQL query.
This is my table structure
Id int Unchecked
Col_A int Unchecked
Col_B int Unchecked
Total int Checked
sql
|
show 6 more comments
I have a Three columns in the SQL table,
I want to show the sum of the total of two columns in the third column. How can I show that using SQL query.
This is my table structure
Id int Unchecked
Col_A int Unchecked
Col_B int Unchecked
Total int Checked
sql
Do you want to select the sum or store the sum in the table?
– juergen d
Jan 15 '15 at 7:50
Check out GROUP BY combined with the aggreagte function SUM, and then do a UNION ALL.
– jarlh
Jan 15 '15 at 7:50
@juergend I want to store the sum in thetotal
column
– user3755380
Jan 15 '15 at 7:51
@jarlh: How can we do that ?
– user3755380
Jan 15 '15 at 7:51
Then you need triggers that update the column value if one of the other changes
– juergen d
Jan 15 '15 at 7:52
|
show 6 more comments
I have a Three columns in the SQL table,
I want to show the sum of the total of two columns in the third column. How can I show that using SQL query.
This is my table structure
Id int Unchecked
Col_A int Unchecked
Col_B int Unchecked
Total int Checked
sql
I have a Three columns in the SQL table,
I want to show the sum of the total of two columns in the third column. How can I show that using SQL query.
This is my table structure
Id int Unchecked
Col_A int Unchecked
Col_B int Unchecked
Total int Checked
sql
sql
edited Jan 15 '15 at 8:11
Sathyajith Bhat
16.2k2084117
16.2k2084117
asked Jan 15 '15 at 7:49
user3755380
Do you want to select the sum or store the sum in the table?
– juergen d
Jan 15 '15 at 7:50
Check out GROUP BY combined with the aggreagte function SUM, and then do a UNION ALL.
– jarlh
Jan 15 '15 at 7:50
@juergend I want to store the sum in thetotal
column
– user3755380
Jan 15 '15 at 7:51
@jarlh: How can we do that ?
– user3755380
Jan 15 '15 at 7:51
Then you need triggers that update the column value if one of the other changes
– juergen d
Jan 15 '15 at 7:52
|
show 6 more comments
Do you want to select the sum or store the sum in the table?
– juergen d
Jan 15 '15 at 7:50
Check out GROUP BY combined with the aggreagte function SUM, and then do a UNION ALL.
– jarlh
Jan 15 '15 at 7:50
@juergend I want to store the sum in thetotal
column
– user3755380
Jan 15 '15 at 7:51
@jarlh: How can we do that ?
– user3755380
Jan 15 '15 at 7:51
Then you need triggers that update the column value if one of the other changes
– juergen d
Jan 15 '15 at 7:52
Do you want to select the sum or store the sum in the table?
– juergen d
Jan 15 '15 at 7:50
Do you want to select the sum or store the sum in the table?
– juergen d
Jan 15 '15 at 7:50
Check out GROUP BY combined with the aggreagte function SUM, and then do a UNION ALL.
– jarlh
Jan 15 '15 at 7:50
Check out GROUP BY combined with the aggreagte function SUM, and then do a UNION ALL.
– jarlh
Jan 15 '15 at 7:50
@juergend I want to store the sum in the
total
column– user3755380
Jan 15 '15 at 7:51
@juergend I want to store the sum in the
total
column– user3755380
Jan 15 '15 at 7:51
@jarlh: How can we do that ?
– user3755380
Jan 15 '15 at 7:51
@jarlh: How can we do that ?
– user3755380
Jan 15 '15 at 7:51
Then you need triggers that update the column value if one of the other changes
– juergen d
Jan 15 '15 at 7:52
Then you need triggers that update the column value if one of the other changes
– juergen d
Jan 15 '15 at 7:52
|
show 6 more comments
5 Answers
5
active
oldest
votes
You can use comuted column for this:
CREATE TABLE [dbo].[Test](
[a] [INT] NULL,
[b] [INT] NULL,
[c] AS ([a]+[b])
) ON [PRIMARY]
GO
INSERT INTO dbo.Test
( a, b )
VALUES ( 1, -- a - int
2 -- b - int
)
SELECT * FROM dbo.Test
Results:
a b c
1 2 3
Thanks giorgi, it worked. Thats what I wanted
– user3755380
Jan 15 '15 at 8:05
Also giorgi, what if I want to show the total for each column. Lets take for column A has 10 records.1+ 1+ 1+ ...
and at the last I have to show the total of these10
records, how to show that ?
– user3755380
Jan 15 '15 at 8:32
@Nadeem - You need to ask a new question and also you should show some effort to solve your problem
– Pரதீப்
Jan 15 '15 at 8:34
SELECT SUM(c) FROM dbo.Test WHERE --apply appropriate filters
– Giorgi Nakeuri
Jan 15 '15 at 8:35
@NoDisplayName: I think the issue is related to the same scenario if I guess..
– user3755380
Jan 15 '15 at 8:35
|
show 6 more comments
There is no need to store the total in the table, you can simply calculate it as part of your SQL query as follows:
SELECT
Id,
Col_A,
Col_B,
Col_A + Col_B AS Total
FROM tablename
add a comment |
Here is my table where the colums are salary and variable.
Now i need the sum of basic and variable as total.
Here is the query for that-
select basic,variable,(basic+variable) as total from salary
add a comment |
or if you just want to display total:
add a comment |
Try the following -
ALTER TABLE TABLENAME ADD colC AS ColA * ColB
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f27958801%2ftotal-sum-of-two-columns-and-show-in-the-third-column%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
5 Answers
5
active
oldest
votes
5 Answers
5
active
oldest
votes
active
oldest
votes
active
oldest
votes
You can use comuted column for this:
CREATE TABLE [dbo].[Test](
[a] [INT] NULL,
[b] [INT] NULL,
[c] AS ([a]+[b])
) ON [PRIMARY]
GO
INSERT INTO dbo.Test
( a, b )
VALUES ( 1, -- a - int
2 -- b - int
)
SELECT * FROM dbo.Test
Results:
a b c
1 2 3
Thanks giorgi, it worked. Thats what I wanted
– user3755380
Jan 15 '15 at 8:05
Also giorgi, what if I want to show the total for each column. Lets take for column A has 10 records.1+ 1+ 1+ ...
and at the last I have to show the total of these10
records, how to show that ?
– user3755380
Jan 15 '15 at 8:32
@Nadeem - You need to ask a new question and also you should show some effort to solve your problem
– Pரதீப்
Jan 15 '15 at 8:34
SELECT SUM(c) FROM dbo.Test WHERE --apply appropriate filters
– Giorgi Nakeuri
Jan 15 '15 at 8:35
@NoDisplayName: I think the issue is related to the same scenario if I guess..
– user3755380
Jan 15 '15 at 8:35
|
show 6 more comments
You can use comuted column for this:
CREATE TABLE [dbo].[Test](
[a] [INT] NULL,
[b] [INT] NULL,
[c] AS ([a]+[b])
) ON [PRIMARY]
GO
INSERT INTO dbo.Test
( a, b )
VALUES ( 1, -- a - int
2 -- b - int
)
SELECT * FROM dbo.Test
Results:
a b c
1 2 3
Thanks giorgi, it worked. Thats what I wanted
– user3755380
Jan 15 '15 at 8:05
Also giorgi, what if I want to show the total for each column. Lets take for column A has 10 records.1+ 1+ 1+ ...
and at the last I have to show the total of these10
records, how to show that ?
– user3755380
Jan 15 '15 at 8:32
@Nadeem - You need to ask a new question and also you should show some effort to solve your problem
– Pரதீப்
Jan 15 '15 at 8:34
SELECT SUM(c) FROM dbo.Test WHERE --apply appropriate filters
– Giorgi Nakeuri
Jan 15 '15 at 8:35
@NoDisplayName: I think the issue is related to the same scenario if I guess..
– user3755380
Jan 15 '15 at 8:35
|
show 6 more comments
You can use comuted column for this:
CREATE TABLE [dbo].[Test](
[a] [INT] NULL,
[b] [INT] NULL,
[c] AS ([a]+[b])
) ON [PRIMARY]
GO
INSERT INTO dbo.Test
( a, b )
VALUES ( 1, -- a - int
2 -- b - int
)
SELECT * FROM dbo.Test
Results:
a b c
1 2 3
You can use comuted column for this:
CREATE TABLE [dbo].[Test](
[a] [INT] NULL,
[b] [INT] NULL,
[c] AS ([a]+[b])
) ON [PRIMARY]
GO
INSERT INTO dbo.Test
( a, b )
VALUES ( 1, -- a - int
2 -- b - int
)
SELECT * FROM dbo.Test
Results:
a b c
1 2 3
answered Jan 15 '15 at 7:54
Giorgi NakeuriGiorgi Nakeuri
31.3k72556
31.3k72556
Thanks giorgi, it worked. Thats what I wanted
– user3755380
Jan 15 '15 at 8:05
Also giorgi, what if I want to show the total for each column. Lets take for column A has 10 records.1+ 1+ 1+ ...
and at the last I have to show the total of these10
records, how to show that ?
– user3755380
Jan 15 '15 at 8:32
@Nadeem - You need to ask a new question and also you should show some effort to solve your problem
– Pரதீப்
Jan 15 '15 at 8:34
SELECT SUM(c) FROM dbo.Test WHERE --apply appropriate filters
– Giorgi Nakeuri
Jan 15 '15 at 8:35
@NoDisplayName: I think the issue is related to the same scenario if I guess..
– user3755380
Jan 15 '15 at 8:35
|
show 6 more comments
Thanks giorgi, it worked. Thats what I wanted
– user3755380
Jan 15 '15 at 8:05
Also giorgi, what if I want to show the total for each column. Lets take for column A has 10 records.1+ 1+ 1+ ...
and at the last I have to show the total of these10
records, how to show that ?
– user3755380
Jan 15 '15 at 8:32
@Nadeem - You need to ask a new question and also you should show some effort to solve your problem
– Pரதீப்
Jan 15 '15 at 8:34
SELECT SUM(c) FROM dbo.Test WHERE --apply appropriate filters
– Giorgi Nakeuri
Jan 15 '15 at 8:35
@NoDisplayName: I think the issue is related to the same scenario if I guess..
– user3755380
Jan 15 '15 at 8:35
Thanks giorgi, it worked. Thats what I wanted
– user3755380
Jan 15 '15 at 8:05
Thanks giorgi, it worked. Thats what I wanted
– user3755380
Jan 15 '15 at 8:05
Also giorgi, what if I want to show the total for each column. Lets take for column A has 10 records.
1+ 1+ 1+ ...
and at the last I have to show the total of these 10
records, how to show that ?– user3755380
Jan 15 '15 at 8:32
Also giorgi, what if I want to show the total for each column. Lets take for column A has 10 records.
1+ 1+ 1+ ...
and at the last I have to show the total of these 10
records, how to show that ?– user3755380
Jan 15 '15 at 8:32
@Nadeem - You need to ask a new question and also you should show some effort to solve your problem
– Pரதீப்
Jan 15 '15 at 8:34
@Nadeem - You need to ask a new question and also you should show some effort to solve your problem
– Pரதீப்
Jan 15 '15 at 8:34
SELECT SUM(c) FROM dbo.Test WHERE --apply appropriate filters
– Giorgi Nakeuri
Jan 15 '15 at 8:35
SELECT SUM(c) FROM dbo.Test WHERE --apply appropriate filters
– Giorgi Nakeuri
Jan 15 '15 at 8:35
@NoDisplayName: I think the issue is related to the same scenario if I guess..
– user3755380
Jan 15 '15 at 8:35
@NoDisplayName: I think the issue is related to the same scenario if I guess..
– user3755380
Jan 15 '15 at 8:35
|
show 6 more comments
There is no need to store the total in the table, you can simply calculate it as part of your SQL query as follows:
SELECT
Id,
Col_A,
Col_B,
Col_A + Col_B AS Total
FROM tablename
add a comment |
There is no need to store the total in the table, you can simply calculate it as part of your SQL query as follows:
SELECT
Id,
Col_A,
Col_B,
Col_A + Col_B AS Total
FROM tablename
add a comment |
There is no need to store the total in the table, you can simply calculate it as part of your SQL query as follows:
SELECT
Id,
Col_A,
Col_B,
Col_A + Col_B AS Total
FROM tablename
There is no need to store the total in the table, you can simply calculate it as part of your SQL query as follows:
SELECT
Id,
Col_A,
Col_B,
Col_A + Col_B AS Total
FROM tablename
answered Jan 15 '15 at 7:54
AlanAlan
2,6272816
2,6272816
add a comment |
add a comment |
Here is my table where the colums are salary and variable.
Now i need the sum of basic and variable as total.
Here is the query for that-
select basic,variable,(basic+variable) as total from salary
add a comment |
Here is my table where the colums are salary and variable.
Now i need the sum of basic and variable as total.
Here is the query for that-
select basic,variable,(basic+variable) as total from salary
add a comment |
Here is my table where the colums are salary and variable.
Now i need the sum of basic and variable as total.
Here is the query for that-
select basic,variable,(basic+variable) as total from salary
Here is my table where the colums are salary and variable.
Now i need the sum of basic and variable as total.
Here is the query for that-
select basic,variable,(basic+variable) as total from salary
answered Jan 14 '18 at 15:55
Debendra DashDebendra Dash
2,2911922
2,2911922
add a comment |
add a comment |
or if you just want to display total:
add a comment |
or if you just want to display total:
add a comment |
or if you just want to display total:
or if you just want to display total:
answered Sep 3 '18 at 14:56
yellow_flash11yellow_flash11
177
177
add a comment |
add a comment |
Try the following -
ALTER TABLE TABLENAME ADD colC AS ColA * ColB
add a comment |
Try the following -
ALTER TABLE TABLENAME ADD colC AS ColA * ColB
add a comment |
Try the following -
ALTER TABLE TABLENAME ADD colC AS ColA * ColB
Try the following -
ALTER TABLE TABLENAME ADD colC AS ColA * ColB
edited Mar 8 at 9:54
Tushar Walzade
2,38131935
2,38131935
answered Mar 8 at 9:33
TaiwoTaiwo
1
1
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f27958801%2ftotal-sum-of-two-columns-and-show-in-the-third-column%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Do you want to select the sum or store the sum in the table?
– juergen d
Jan 15 '15 at 7:50
Check out GROUP BY combined with the aggreagte function SUM, and then do a UNION ALL.
– jarlh
Jan 15 '15 at 7:50
@juergend I want to store the sum in the
total
column– user3755380
Jan 15 '15 at 7:51
@jarlh: How can we do that ?
– user3755380
Jan 15 '15 at 7:51
Then you need triggers that update the column value if one of the other changes
– juergen d
Jan 15 '15 at 7:52