Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Sum function sql statement

 
Loh Peggie
Ranch Hand
Posts: 51
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey guys do you know how to implement the sql statement for the sum unit price in jsp?

This is my code:


But the problem is I do not know how to add in the sum UnitPrice.


Thanks
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Aggregate functions just take the field you are interested in as a parameter. So:

notice you will have to add a group by for all fields not in the function for it to work.

 
Loh Peggie
Ranch Hand
Posts: 51
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
However my table is in t form of inner join.

Currently I am doing a shopping cart and I need to make use of inner join statement to display the details.

The two database that I make use of is called:
shoppingcartitems
Products
I link them together by using the productId

My shoppingcartitems attributes are:
SCId
UserId
ProductId
Quantity


My products attributes are:
ProductId
ProdName
ProdColor
ProdDesc
UnitPrice
Quantity
ProdCatId
UserId
ProdImage


The shopping cart will display ProdImage, UnitPrice, ProductName, quantity and TotalPrice(But i dont know how to write the sql statement that sum the unit price from the database)

Thanks
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The join doesn't make a difference, the logic is still the same. To flesh it out a bit:

 
Loh Peggie
Ranch Hand
Posts: 51
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks

Erm may I know is my sql statement correct:



Thanks!
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No, you need to group things not in your aggregate function.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic