sum

MYSQL SUM GROUP BY

I'm working on a high school grading system. At my school, grades can be changed by reworking problems and I store these changes with dates. I have a function that properly returns averages because the most recent grade is flagged with a "current" field with a value of '1'. I'd like to make the function capable of returning the most re...

In xsl, is there a way to next a normalize-space call inside a sum?

I have an XML file that has a number of nodes, each of which contains a <current-fine> node. I need to sum these values but unfortunately they contain white-space so I end up getting NaN as the total. Is there a way of achieving the following: <xsl:value-of select="sum(normalize-space(node/sub-node/current-fine))"/> Many thanks ...

MATLAB: Why is this summation not working properly?

I'm trying to perform a really simple summation in MATLAB. Here is my code: moment = 0; for y=1:rows, for x=1:cols, moment = moment + (x^p * y^q * Im(y,x)); end end I want (x^p * y^q * Im(y,x)) to be calculated for each iteration and added to the moment variable, but this function is returning the moment the first tim...

LinQ how to multiplay inside a SUM method

solved: IstBestellwert = grouped.Sum(o => (double)o.SollMenge * (double)o.Preis) works My SQL Statment SELECT ABId, SUM(Preis * IstMenge) AS IstBestellwert, SUM(Preis * SollMenge) AS SollBestellwert FROM vChainStoreOrderingDetails GROUP BY ABId, FilialId HAVING (ABId = 10) AND (FilialId IN (8, 140)) ...

How can I display a total for a calculated column in a SharePoint list?

I have a column, B, that is calculated based on another column, A. At the top of the list, I'd like to display the sum of B. When I look in the Totals section in the Create/Modify a Column screen, I only see column A (actually, I only see all the non-calculated columns), so I can't choose to sum column B. Is there a way to display a tot...

Calculating percentages with SQL

I'm trying to create an SQL query to work out the percentage of rows given its number of play counts. My DB currently has 800 rows of content, All content has been played a total of 3,000,000 times put together table: *id, play_count, content* Lets say I'd like to work out the percentage of the first 10 rows. My attempts have looked ...

Simple math question with LinQ, simple Join query, Nulls, etc.

I have 2 tables   1. Client   2. Operations Operations can result in: Credits or Debits ('C' or 'D' in a char field) along with date and ammount fields. I must calculate the balance for each client's account using linQ... The result should also show balance 0 for clients whom didn't make operations yet I have the following function wi...

how to calculate sum of hours?

My tables are as follows workers: id integer ... days: id INTEGER event_date DATE worker_id INTEGER and hours: id INTEGER hr_start VARCHAR2(8) hr_stop VARCHAR2(8) day_id INTEGER I need a function which will calculate for every user in database, sum of hours in current month. ...

Problem with Crystal Reports

Hi I have a problem with Sum fields in Crystal Reports, under VS 2003. I am using VS 2003 and Crystal Reports to generate a report with data retrieved from a SQL Server 2000 database and kept during runtime inside a strongly typed dataset. The dataset contains several tables, one of which, the orders table, receives the results of a SQ...

Python: next() function

I'm learning Python from a book, and I came across this example: M = [[1,2,3], [4,5,6], [7,8,9]] G = (sum(row) for row in M) # create a generator of row sums next(G) # Run the iteration protocol Since I'm an absolute beginner, and the author hasn't provided any explanation of the example or the next() function, I don't unde...

RoR: How to Change fields on Join statement generated by Active Record's sum function.

I'm doing a sum using the Sum function provided by RubyOnRails' Active Record as follows: s=DatosMateria.sum('inscritos',:conditions=> "datos_materia.ano=2005 AND materias.codigo=2394",:include=>"materias") it returns 0 and generates me the following SQL statement: SELECT sum('datos_materia'.inscritos) AS sum_inscritos FROM 'datos_m...

Sum and Division example (Python)

>>> sum((1, 2, 3, 4, 5, 6, 7)) 28 >>> 28/7 4.0 >>> sum((1,2,3,4,5,6,7,8,9,10,11,12,13,14)) 105 >>> 105/7 15.0 >>> How do I automate this sum and division using a loop maybe? Edit: Maybe I wasn't clear - I want a loop to keep doing the sum (of multiples of 7, eg 1-7, 1-14, 1-21 etc..) until it reaches x (x is the user input) Okay, fig...

Sum values of a loop

hi i have this : <% for item in @ventas_ocurridas_en_este_periodo do %> <% @pid = item.producto_id %> <br/> Producto: <%= Producto.find_by_id(@pid) %><br/> Costo de Compra: <%= @costo_de_compra = Producto.find(:all, :conditions => "id = '#{@pid}'").*.costo_de_compra %><br/> Precio de venta: <%= @precio_de_venta = item.precio_de_venta ...

insert a value into an integer column without updating it, but adding it's contents.

hello i have: ActiveRecord::Base.connection.execute "UPDATE ventas SET costo_de_compra = #{@nuevo_costo} WHERE id = #{@vid};" but this updates that column value every time it's recursed, what i want is just to insert that value to the already stablished values in that column... in proper instance i want to add the values to an intege...

SELECT command to calculate percentage

I'm trying to get the percentage of each video I have in my database based on its view count against all other videos. I'm then trying to display all the videos from highest view count to lowest, displaying its percentage on its side inside a nice HTML page. Obviously the percentage would range from 0 - 100% (and not over) and the mos...

MAX on columns generated by SUM and GROUP BY

I'm trying to get the MAX on a column which is generated dynamically using the SUM statement. The SUM statement is used together with the 'GROUP by' syntax. This is the original query, however it needs to be modified to work with grouping, sums and of course MAX. SELECT SUM(video_plays) AS total_video_plays FROM `video_statistics`...

How to do: sum columnB where columnA is XYZ - in Excel?

Hi I have a bunch of columns and some columns which are values I need to add. Lets say I want to sum columnB (which could be $) where column A is banana, how do I do that? Thing is I have a huge dataset and it is something that is going to keep changing. And besides banana, i might have apples, oranges, etc. And I want to sum the $ val...

Linq - 2 tables - Sum

Hi, i have 2 tables: Asiento ******** Id_Asiento integer key Fecha date It_Asiento ********** Id_Asiento integer Forenkey Importe float I wan to do This SQL Query with Linq select Asiento.Id_Asiento, Asiento.Fecha, Sum(It_Asiento.Importe) From Asiento join It_Asiento on Asiento.Id_Asiento = It_Asiento.Id_Asiento and It_Asiento.Im...

LINQ: query to sum on grouped field

I've a list of tasks. Ie I've struct like struct Task { public DateTime Completed { get; set; } public string TaskKind { get; set; } public float Effort { get; set; } } And I've a IList<Task>. Now I want to group the tasks based on the date and group by TaskKind on each day with the summed effort. For eg for I want to pri...

VB.NET LINQ Query: Getting The Sum of All Values For A Specific Structure Member

Greetings: In VB.NET, let's assume I have the following Structure: Public Structure Product Public ItemNo As Int32 Public Description As String Public Cost As Decimal End Structure ... and a Generic List of the Products: Dim ProductsList As New List(Of Product) Dim product1 As New Product With product1 .ItemNo = 10...