Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8059973
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T09:50:20+00:00 2026-06-05T09:50:20+00:00

I have a view with fields: typeId, type int price, type decimal(15,4)) Price is

  • 0

I have a view with fields:

typeId, type int
price, type decimal(15,4))

Price is calculated value.

What I would like is to add another calculated column (totalPrice) in the select statement that would sum all prices for records with same id giving me the result (assuming there are four rows in the view):

typeId   price         totalPrice
1        10,000        30,000
1        15,000        30,000
1        5,000         30,000
2        10,000        10,000

Thank you.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T09:50:21+00:00Added an answer on June 5, 2026 at 9:50 am

    Assuming your existing view is named TheSummary. Rename it to x_TheSummary

    Create a new view which bears the old name of the renamed view.

    create view TheSummary as
    
    select x.*, g.totalPrice
    from x_TheSummary x
    join
    (
        select typeId, sum(price) as totalPrice
        from x_TheSummary
        group by typeId
    ) as g on g.typeId = x.typeId
    

    This way, your new view won’t have any breaking changes to apps that depends on old view name

    By the way, since you are using SQL Server 2008, you can use the following windowing-query too, the query above works on non-windowing-capable RDBMS though.

    create view TheSummary as
    
    select x.*, sum(totalPrice partition by typeId) as totalPrice
    from x_TheSummary x
    

    It’s a lot simpler


    @ivan-83 For a second, I thought SQL Server 2008 doesn’t support windowing on partition. I’m thinking too much of this construct(running total) that doesn’t work on SQL 2008, yet it works on SQL 2012.

    SELECT  i, sum(i) over(order by i) as rt
    FROM    (values(1),(9),(7),(6)) as x(i)
    

    The running total query doesn’t work on SQL 2008: http://www.sqlfiddle.com/#!3/d41d8/1539

    And it now works on SQL 2012: http://www.sqlfiddle.com/#!6/d41d8/111

    Outputs:

    | I | RT |
    ----------
    | 1 |  1 |
    | 6 |  7 |
    | 7 | 14 |
    | 9 | 23 |
    

    To sum it up, SQL Server 2012 not only it supports windowing on partition, it also supports windowing on row-by-row basis. SQL Server 2008 supports windowing on partition only. So @ivan-83 solutions works too. For this, I upvote your answer

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hey, I have a table with 2 fields of type int which are StatusID
I have a relation Game belongsTo Type. In the add view of game, i
I have a view with some fields (name, email, password, register button) : <ScrollView
I have a grid view with template fields and can bind data into it.
I have a view model with a property Fields which is an ObservableCollection<FieldVM> .
I have two text fields in my view. I did it using IB. My
I have the following problem: I got a view with two text fields and
I have a table contents many fields db.define_table('i2l_templates', Field('id','id', represent=lambda id:SPAN(A(T('View'),_href=URL('view_template',args=id)),' | ', A(T('Edit'),_href=URL('edit_template',args=id)))),
Say I have a strongly-typed view of ViewPage<Song> and some additional fields in the
I Have a View stronger Typed, of my class called Cliente , Defined like

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.