Search Results

Search found 2210 results on 89 pages for 'sum'.

Page 10/89 | < Previous Page | 6 7 8 9 10 11 12 13 14 15 16 17  | Next Page >

  • Same Data Appear only once.

    - by friendishan
    I have the following code which produces following output:- <? $tablaes = mysql_query("SELECT * FROM members where id='$order[user_id]'"); $user = mysql_fetch_array($tablaes); $idsd=$user['id']; $rPaid=mysql_query("SELECT SUM(`price`) AS total FROM order_history WHERE type!='rent_referral' AND date>'" . strtotime($time1) . "' AND date<'" . strtotime($time2) . "'"); $hdPaid = mysql_fetch_array($rPaid); $sPaid=mysql_query("SELECT SUM(`price`) AS total FROM order_history WHERE user_id='$idsd' AND type!='rent_referral' AND date>'" . strtotime($time1) . "' AND date<'" . strtotime($time2) . "'"); while ($hPaid = mysql_fetch_array($sPaid)) { ?> <td><?=$user['username']?></td> <td><?=$hPaid['total']?></td> <? } ?> </tr> It appears like this http://dl.dropbox.com/u/14384295/darrenan.jpg I want same data to appear only once.. Like Username: Vegas and price with him only once.

    Read the article

  • Numerology with Python And Django

    - by Asinox
    Hi guys, i have a function that give me the result that im expecting in console mode, but if i try to use the function with Django, the page never load and just have a loop calculating and never end. Any idea ? *sorry with my english Console function (WORK GREAT): def sum_digitos(n): sum = 0; while n != 0: sum += n % 10 n /= 10 if sum > 9: x = str(sum) y =list(x) sum = int(y[0]) + int(y[1]) return sum print sum_digitos(2461978) Django views: def Calcular(request): if request.method == 'POST': form = NumerologiaForm(request.POST) if form.is_valid(): sum = 0; ano = str(request.POST['fecha_year']) mes = str(request.POST['fecha_month']) dia = str(request.POST['fecha_day']) data = dia + mes + ano fecha = int(data) while fecha != 0: f = fecha sum += f % 10 f /= 10 if sum > 9: x = str(sum) y =list(x) sum = int(y[0]) + int(y[1]) resultado = get_object_or_404(Numero,numero = sum) return HttpResponseRedirect(resultado.get_absolute_url()) else: form = NumerologiaForm() return render_to_response('numerologiaForm.html',{'form':form})

    Read the article

  • Summing / Running totals

    - by John
    I have 4 columns: Name, Week, Batch and Units Produced (Cols, A,b,c,d). In column e, I need to keep running totals based on name and week. When the week changes for the same person, restart the total. Fred, 12, 4001, 129.0 Answer in e: 129.0 Fred, 12, 4012, 234.0 Answer in e: 363.0 Fred, 13, 4023, 12.0 Answer in e: 12.0 John, 12, 4003, 420.0 Answer in e: 420.0 John, 13, 4021, 1200.0 Answer in e: 1200.0 John, 13, 4029, 120.0 Answer in e: 1320.0 I need to be able to copy the formula to over 1000 rows.

    Read the article

  • LEFT OUTER JOIN SUM doubles problem

    - by Michael
    Hi I've got two tables: Table: Shopping shop_id shop_name shop_time 1 Brian 40 2 Brian 31 3 Tom 20 4 Brian 30 Table:bananas banana_id banana_amount banana_person 1 1 Brian 2 1 Brian I now want it to print: Name: Tom | Time: 20 | Bananas: 0 Name: Brian | Time: 101 | Bananas: 2 I used this code: $result = dbquery("SELECT tz.*, tt.*, SUM(shop_time) as shoptime, count(banana_amount) as bananas FROM shopping tt LEFT OUTER JOIN bananas tz ON tt.shop_name=tz.banana_person GROUP by banana_person LIMIT 40 "); while ($data5 = dbarray($result)) { echo 'Name: '.$data5["shop_name"].' | Time: '.$data5["shoptime"].' | Bananas: '.$data5["bananas"].'<br>'; } The problem is that I get this instead: Name: Tom | Time: 20 | Bananas: 0 Name: Brian | Time: 202 | Bananas: 6 I just don't know how to get around this.

    Read the article

  • MySQL - getting SUM of MAX results from 2 tables

    - by SODA
    Hi, Here's my problem: I have 2 identical tables (past month data, current month data) - data_2010_03, data_2010_04: Content_type (VARCHAR), content_id (INT), month_count (INT), pubDate (DATETIME) Data in month_count is updated hourly, so for each combination of content_type and content_id we insert new row, where value of month_count is incrementally updated. Now I try something like this: SELECT MAX(t1.month_count) AS max_1, MAX(t2.month_count) AS max_2, SUM(max_1 + max_2) AS result, t1.content_type, t1.content_id FROM data_2010_03 AS t1 JOIN data_2010_04 AS t2 ON t1.content_type = t2.content_type AND t1.content_id = t2.content_id WHERE t2.pubDate < '2010-04-08' AND t1.content_type = 'video' GROUP BY t1.content_id ORDER BY result desc, max_1 desc, max_2 desc LIMIT 0,10 I get an error "Unknown column 'max_1' in 'field list'. Please help.

    Read the article

  • Subset sum problem

    - by MadBoy
    I'm having a problem with counting which is continuation of this question. I am not really a math person so it's really hard for me to figure out this subset sum problem which was suggested as resolution. I'm having 4 ArrayList in which I hold data: alId, alTransaction, alNumber, alPrice Type | Transaction | Number | Price 8 | Buy | 95.00000000 | 305.00000000 8 | Buy | 126.00000000 | 305.00000000 8 | Buy | 93.00000000 | 306.00000000 8 | Transfer out | 221.00000000 | 305.00000000 8 | Transfer in | 221.00000000 | 305.00000000 8 | Sell | 93.00000000 | 360.00000000 8 | Sell | 95.00000000 | 360.00000000 8 | Sell | 126.00000000 | 360.00000000 8 | Buy | 276.00000000 | 380.00000000 In the end I'm trying to get what's left for customer and what's left I put into 3 array lists: alNew (corresponds to alNumber), alNewPoIle (corresponds to alPrice), and alNewCo (corrseponds to alID) ArrayList alNew = new ArrayList(); ArrayList alNewPoIle = new ArrayList(); ArrayList alNewCo = new ArrayList(); for (int i = 0; i < alTransaction.Count; i++) { string tempAkcjeCzynnosc = (string) alTransaction[i]; string tempAkcjeInId = (string) alID[i]; decimal varAkcjeCena = (decimal) alPrice[i]; decimal varAkcjeIlosc = (decimal) alNumber[i]; int index; switch (tempAkcjeCzynnosc) { case "Transfer out": case "Sell": index = alNew.IndexOf(varAkcjeIlosc); if (index != -1) { alNew.RemoveAt(index); alNewPoIle.RemoveAt(index); alNewCo.RemoveAt(index); } else { ArrayList alTemp = new ArrayList(); decimal varAkcjeSuma = 0; for (int j = 0; j < alNew.Count; j ++) { string akcjeInId = (string) alNewCo[j]; decimal akcjeCena = (decimal) alNewPoIle[j]; decimal akcjeIlosc = (decimal) alNew[j]; if (tempAkcjeInId == akcjeInId && akcjeCena == varAkcjeCena) { alTemp.Add(j); varAkcjeSuma = varAkcjeSuma + akcjeIlosc; } } if (varAkcjeSuma == varAkcjeIlosc) { for (int j = alTemp.Count -1 ; j >=0 ; j --) { int tempIndex = (int) alTemp[j]; alNew.RemoveAt(tempIndex); alNewPoIle.RemoveAt(tempIndex); alNewCo.RemoveAt(tempIndex); } } } break; case "Transfer In": case "Buy": alNew.Add(varAkcjeIlosc); alNewPoIle.Add(varAkcjeCena); alNewCo.Add(tempAkcjeInId); break; } } Basically I'm adding and removing things from Array depending on Transaction Type, Transaction ID and Numbers. I'm adding numbers to ArrayList like 156, 340 (when it is TransferIn or Buy) etc and then i remove them doing it like 156, 340 (when it's TransferOut, Sell). My solution works for that without a problem. The problem I have is that for some old data employees were entering sum's like 1500 instead of 500+400+100+500. How would I change it so that when there's Sell/TransferOut or Buy/Transfer In and there's no match inside ArrayList it should try to add multiple items from thatArrayList and find elements that combine into aggregate. Inside my code I tried to resolve that problem with simple summing everything when there's no match (index == 1) if (index != -1) { alNew.RemoveAt(index); alNewPoIle.RemoveAt(index); alNewCo.RemoveAt(index); } else { ArrayList alTemp = new ArrayList(); decimal varAkcjeSuma = 0; for (int j = 0; j < alNew.Count; j ++) { string akcjeInId = (string) alNewCo[j]; decimal akcjeCena = (decimal) alNewPoIle[j]; decimal akcjeIlosc = (decimal) alNew[j]; if (tempAkcjeInId == akcjeInId && akcjeCena == varAkcjeCena) { alTemp.Add(j); varAkcjeSuma = varAkcjeSuma + akcjeIlosc; } } if (varAkcjeSuma == varAkcjeIlosc) { for (int j = alTemp.Count -1 ; j >=0 ; j --) { int tempIndex = (int) alTemp[j]; alNew.RemoveAt(tempIndex); alNewPoIle.RemoveAt(tempIndex); alNewCo.RemoveAt(tempIndex); } } But it only works if certain conditions are met, and fails for the rest.

    Read the article

  • How to calculate running totals of subsets of data in a table

    - by John
    I have 4 columns: Name, Week, Batch and Units Produced (Cols, A,B,C,D). In column E, I need to keep running totals based on name and week. When the week changes for the same person, restart the total. Fred, 12, 4001, 129.0 Answer in e: 129.0 Fred, 12, 4012, 234.0 Answer in e: 363.0 Fred, 13, 4023, 12.0 Answer in e: 12.0 John, 12, 4003, 420.0 Answer in e: 420.0 John, 13, 4021, 1200.0 Answer in e: 1200.0 John, 13, 4029, 120.0 Answer in e: 1320.0 I need to be able to copy the formula to over 1000 rows.

    Read the article

  • Express any number as the sum of 4 prime numbers [Doubts]

    - by WarDoGG
    I was give a problem to express any number as sum of 4 prime numbers. Conditions: Not allowed to use any kind of database. Maximum execution time : 3 seconds Numbers only till 100,000 If the splitting is NOT possible, then return -1 What i did : using the sieve of eratosthenes, i calculated all prime numbers till the specified number. looked up a concept called goldbach conjecture which expresses an even number as the summation of 2 primes. However, i am stuck beyond that. Can anyone help me on this one as to what approach u might take ? The sieve of eratosthenes is taking 2 seconds to count primes till 100,000 :(((

    Read the article

  • Positive result, negative result and current balance. How do you make starting balance show current result?

    - by Tine
    I have 3 columns. Column A shows positive result and if the result is negative then it is in a column B. Column B shows negative result and if the result is positive then it is in a column A. (meaning that either columns can have 0.00 in the cell (empty zero cells)). Column C has starting assets and it also shows the current balance that while result A or B are adding up and current balance is showing the current result. What is the proper formula for this I hope I was clear with my problem. Please help. Thanks in advance!

    Read the article

  • Rails/mysql SUM distinct records - optimization

    - by pepernik
    Hey. How would you optimize this SQL SELECT SUM(tmp.cost) FROM ( SELECT DISTINCT clients.id as client, countries.credits_cost AS cost FROM countries INNER JOIN clients ON clients.country_id = countries.id INNER JOIN clients_groups ON clients_groups.client_id=clients.id WHERE clients_groups.group_id IN (1,2,3,4,5,6,7,8,9) GROUP BY clients.id ) AS tmp; I'm using this example as part of my Ruby on Rails project. Note that my nested SQL (tmp) can have more then 10 milion records. You can split that in more SQLs if the performance is better. Should I add any indexes to make it quicker (i have it on IDs)?

    Read the article

  • MDX filter members in a sum-function

    - by Radagast2005
    I have an SSAS cube containing customers and their purchased memberships (let's say magazines). I want to calculate the retention. I.e. how many customers remain a customer. To do this I specify a set (males, 30yrs, 1 january 2011). I want to see if this set - identified by a customer number - is still present in the following months. I named my set MySet2. What I try to do is: sum(measures.amount, [membership].[name].&[X], MySet2, [date].[date].currentmember) However, the result is incorrect. The number is far to low. I suspect it still tries to account for all the males of 30 years old, but after a year they're not 30 anymore. What am I missing? I looked at scope and filter, but I'm not sure how to apply it.

    Read the article

  • Merging tables in MySQL - sum up columns

    - by Alan Williamson
    I have an interesting problem, that i am sure has a simple answer, but i can't seem to find it in the docs. I have two separate database tables, on different servers. They are both identical table schema with the same primary keys. I want to merge the tables together on one server. But, if the row on Server1.Table1 exists in Server2.Table2 then sum up the totals in the columns i specify. Table1{ column_pk, counter }; "test1", 3 "test2", 4 Table2{ column_pk, counter }; "test1", 5 "test2", 6 So after i merge i want: "test1",8 "test2",10 Basically i need to do a mysqldump but instead of it kicking out raw INSERT statements, i need to do a INSERT..ON DUPLICATE KEY UPDATE statements. What are my options? Appreciate any input, thank you

    Read the article

  • tsql sum data and include default values for missing data

    - by markpirvine
    Hi, I would like a query that will shouw a sum of columns with a default value for missing data. For example assume I have a table as follows: type_lookup: id name 1 self 2 manager 3 peer And a table as follows data: id type_lookup_id value 1 1 1 2 1 4 3 2 9 4 2 1 5 2 9 6 1 5 7 2 6 8 1 2 9 1 1 After running a query I would like a result set as follows: type_lookup_id value 1 13 2 25 3 0 I would like all rows in type_lookup table to be included in the result set - even if they don't appear in the data table. Any help would be greatly appreciated, Mark

    Read the article

  • Sum two rows in one - My Sql

    - by user303832
    I have found some similar posts, but I didn't find them useful. But I didn't know how to group them. I would like to Sum 'No' and 'Not Set' to one row, and to lose 'Not Set' row. So : 'No' = 'No' + 'Not Set' I have something like this : TEST TestCount Month 'Yes' 123 March 'No' 432 March 'Not Set' 645 March 'Yes' 13 April 'No' 42 April 'Not Set' 45 April 'Yes' 133 May 'No' 41 May 'Not Set' 35 May .... And I would like something like this : TEST TestCount Month 'Yes' 423 March 'No' 410 March 'Yes' 154 April 'No' 192 April 'Yes' 130 May 'No' 149 May .... Can anybody help me with this, tnx in advance

    Read the article

  • "for" loop from program 7.6 from Kochan's "Programming in Objective-C"

    - by Mr_Vlasov
    "The sigma notation is shorthand for a summation. Its use here means to add the values of 1/2^i, where i varies from 1 to n. That is, add 1/2 + 1/4 + 1/8 .... If you make the value of n large enough, the sum of this series should approach 1. Let’s experiment with different values for n to see how close we get." #import "Fraction.h" int main (int argc, char *argv[]) { NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init]; Fraction *aFraction = [[Fraction alloc] init]; Fraction *sum = [[Fraction alloc] init], *sum2; int i, n, pow2; [sum setTo: 0 over: 1]; // set 1st fraction to 0 NSLog (@"Enter your value for n:"); scanf ("%i", &n); pow2 = 2; for (i = 1; i <= n; ++i) { [aFraction setTo: 1 over: pow2]; sum2 = [sum add: aFraction]; [sum release]; // release previous sum sum = sum2; pow2 *= 2; } NSLog (@"After %i iterations, the sum is %g", n, [sum convertToNum]); [aFraction release]; [sum release]; [pool drain]; return 0; } Question: Why do we have to create additional variable sum2 that we are using in the "for" loop? Why do we need "release previous sum" here and then again give it a value that we just released? : sum2 = [sum add: aFraction]; [sum release]; // release previous sum sum = sum2; Is it just for the sake of avoiding memory leakage? (method "add" initializes a variable that is stored in sum2)

    Read the article

  • Query - Trying to SUM one field based on content of another field

    - by ShaneL
    Table: DayOfWeek Enrollments Monday 35 Monday 12 Saturday 25 Tuesday 15 Monday 9 Tuesday 15 Basically I'm trying to sum the total enrolments for each day. so the Output will look like: DayOfWeek Enrollments Monday 56 Saturday 25 Tuesday 30 I've spent around 4 hours trying to work this out trying many many different ways but no luck. The problem I'm having is i can count how many enrollments for each day but can't have it aligned with the correct day when i run the query e.g. I want The total to be on the same line as the day it was calculated from. (I hope that is clear enough)

    Read the article

  • Fastest possible summing numbers up to N

    - by dada
    Okay so i need really FAST algorithm or code in C if you have any it would be nice. The task is to sum all numbers from 1 to N for a given number N (it can be negative number too), so i did the usual way (you know just summing with loop from 1 to N) but it's not fast enough - i need something faster, i guess that i need the fastest possible way to do this. If anyone could help me, please do. Thanks.

    Read the article

  • Subset Problem -- Any Materials?

    - by bobber205
    Yes this is a homework/lab assignment. I am interesting in coming up with/finding an algorithm (I can comprehend :P) for using "backtracking" to solve the subset sum problem. Anyone have some helpful resources? I've spent the last hour or so Googling with not much like finding something I think I could actually use. xD Thanks SO!

    Read the article

  • Getting the submatrix with maximum sum?

    - by guirgis
    With the help of the Algorithmist and Larry and a modification of Kadane's Algorithm, here is my solution: int dim = matrix.length; //computing the vertical prefix sum for columns int[][] ps = new int[dim][dim]; for (int i = 0; i < dim; i++) { for (int j = 0; j < dim; j++) { if (j == 0) { ps[j][i] = matrix[j][i]; } else { ps[j][i] = matrix[j][i] + ps[j - 1][i]; } } } int maxSoFar = 0; int min , subMatrix; //iterate over the possible combinations applying Kadane's Alg. //int toplefti =0, topleftj=0, bottomrighti=0, bottomrightj=0; for (int i = 0; i < dim; i++) { for (int j = i; j < dim; j++) { min = 0; subMatrix = 0; for (int k = 0; k < dim; k++) { if (i == 0) { subMatrix += ps[j][k]; } else { subMatrix += ps[j][k] - ps[i-1][k]; } if(subMatrix < min){ min = subMatrix; } if((subMatrix - min) > maxSoFar){ maxSoFar = subMatrix - min; } } } } The only problem left is to determine the submatrix elements, i mean the top left and the bottom right corners. I managed to do this in one dimensional case. Any suggestions?

    Read the article

  • C#: Sum of even fibonacci numbers

    - by user300484
    Hello you all! im developping an application that will find the sum of all even terms of the fibonacci sequence. The last term of this sequence is 4,000,000 . There is something wrong in my code but I cannot find the problem since it makes sense to me. Can you please help me? using System.Collections.Generic; using System.Linq; using System.Text; namespace ConsoleApplication1 { class Program { static void Main(string[] args) { long[] arr = new long [1000000] ; long i= 2; arr[i-2]=1; arr[i-1]=2; long n= arr[i]; long s=0; for (i=2 ; n <= 4000000; i++) { arr[i] = arr[(i - 1)] + arr[(i - 2)]; } for (long f = 0; f <= arr.Length - 1; f++) { if (arr[f] % 2 == 0) s += arr[f]; } Console.Write(s); Console.Read(); } } }

    Read the article

  • NSOutlineView/NSTreeController - calculate sum of column

    - by matei
    I have a NSOutlineView bound to a NSTreeController. My data items are a custom class , let's call them "Row", and suppose a Row contains a "name" and a numeric field called "number" . All these "Rows" are found in let's say a "RowContainer" which has a "rows" mutable array holding the parent (level 0) rows. Each row also has a "children" NSMutableArray member which holds it's children. I have this working, and I want to display under the outlineview a textfield with the sum of all the "number" values of the rows. I bound this textfield to a "total" property of the "RowContainer". Now the problem is how or from where to trigger the recalculation of the "total" property, since this involves a recursive walk on the tree of rows, and I always get a "Collection was mutated while being enumerated" error. I've tried making a method "recalculateTotal", and calling it from the "setNumber" method of the "Row" class , but same error occurs. If I put the recalculation logic in the "total" getter, I can't trigger it to do the math. I'm sure the solution is simple but I can't see it

    Read the article

  • Removing an array dimension where the elements sum to zero

    - by James
    Hi, I am assigning a 3D array, which contains some information for a number of different loadcases. Each row in the array defines a particular loadcase (of which there are 3) and I would like to remove the loadcase (i.e. the row) if ALL the elements of the row (in 3D) are equal to zero. The code I have at the moment is: Array = zeros(3,5) % Initialise array Numloadcases = 3; Array(:,:,1) = [10 10 10 10 10; 0 0 0 0 0; 0 0 0 0 0;]; % Expand to a 3D array Array(:,:,2) = [10 10 10 10 10; 0 0 0 0 0; 0 0 0 0 0;]; Array(:,:,3) = [10 10 10 10 10; 0 0 0 0 0; 0 0 20 0 0;]; Array(:,:,4) = [10 10 10 10 10; 0 0 0 0 0; 0 0 20 0 0;]; % I.e. the second row should be removed. for i = 1:Numloadcases if sum(Array(i,:,:)) == 0; Array(i,:,:) = [] end end At the moment, the for loop I have to remove the rows causes an indexing error, as the size of the array changes in the loop. Can anyone see a work around for this? Thanks

    Read the article

  • Simple encryption - Sum of Hashes in C

    - by Dogbert
    I am attempting to demonstrate a simple proof of concept with respect to a vulnerability in a piece of code in a game written in C. Let's say that we want to validate a character login. The login is handled by the user choosing n items, (let's just assume n=5 for now) from a graphical menu. The items are all medieval themed: eg: _______________________________ | | | | | Bow | Sword | Staff | |-----------|-----------|-------| | Shield | Potion | Gold | |___________|___________|_______| The user must click on each item, then choose a number for each item. The validation algorithm then does the following: Determines which items were selected Drops each string to lowercase (ie: Bow becomes bow, etc) Calculates a simple string hash for each string (ie: `bow = b=2, o=15, w=23, sum = (2+15+23=40) Multiplies the hash by the value the user selected for the corresponding item; This new value is called the key Sums together the keys for each of the selected items; this is the final validation hash IMPORTANT: The validator will accept this hash, along with non-zero multiples of it (ie: if the final hash equals 1111, then 2222, 3333, 8888, etc are also valid). So, for example, let's say I select: Bow (1) Sword (2) Staff (10) Shield (1) Potion (6) The algorithm drops each of these strings to lowercase, calculates their string hashes, multiplies that hash by the number selected for each string, then sums these keys together. eg: Final_Validation_Hash = 1*HASH(Bow) + 2*HASH(Sword) + 10*HASH(Staff) + 1*HASH(Shield) + 6*HASH(Potion) By application of Euler's Method, I plan to demonstrate that these hashes are not unique, and want to devise a simple application to prove it. in my case, for 5 items, I would essentially be trying to calculate: (B)(y) = (A_1)(x_1) + (A_2)(x_2) + (A_3)(x_3) + (A_4)(x_4) + (A_5)(x_5) Where: B is arbitrary A_j are the selected coefficients/values for each string/category x_j are the hash values for each string/category y is the final validation hash (eg: 1111 above) B,y,A_j,x_j are all discrete-valued, positive, and non-zero (ie: natural numbers) Can someone either assist me in solving this problem or point me to a similar example (ie: code, worked out equations, etc)? I just need to solve the final step (ie: (B)(Y) = ...). Thank you all in advance.

    Read the article

< Previous Page | 6 7 8 9 10 11 12 13 14 15 16 17  | Next Page >