0

I am a beginner programmer wanna ask about simple SUM query for C#. here is the case:

I have a table called "revenue", and that table consist of 5 columns. they are Bulan, Target, Realisasi, Target_YtD, and Realisasi_YtD. for column Bulan, I manually inserted 12 data. they are January, Februari, March, and so on...

For column Target and Realisasi also I inserted data manually with INT data type.

Now, I wanna add up the January's Target + February's Target + March's Target, and then the value of that calculation is gonna fill March's Target_YtD.

Can somebody tell me the query of that? I hope anyone can help me this time, I really appreciate that. Thanks

3
  • 1
    Seems like a simple database statement, why do you need C# for it? Commented Aug 23, 2016 at 6:18
  • 2
    Have a read through this: stackoverflow.com/help/how-to-ask Commented Aug 23, 2016 at 6:21
  • if you want sql query , you may look in to this, possible duplicate stackoverflow.com/questions/1607720/… Commented Aug 23, 2016 at 6:30

2 Answers 2

1

Do you mean something like this?

UPDATE 
SET Target_YtD =
  (SELECT SUM(Target) AS Total FROM revenue
  WHERE Bulan IN ('JAnuary', 'February', 'March')
)
WHERE Bulan = 'March'
Sign up to request clarification or add additional context in comments.

1 Comment

youre almost there i guess. can i get your email anyway sir? i wanna ask about this problem deeper please.
0

It depends on if you plan to calculate the colum at the time of input and save it to the database. Usually calculated columns are not in and of themselves columns in databases, but if that is what you are doing you can just use the c# concatenation function to populate that variable before doing your insert statement. If you're only populating the sum upon output to a c# app, same thing applies, or you could do a sum in your sql code. A few ways to get there, just depends what you're trying to do.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.