Search Results

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

Page 7/89 | < Previous Page | 3 4 5 6 7 8 9 10 11 12 13 14  | Next Page >

  • Dynamic programming solution to the subset-sum decision problem

    - by Gail
    How can a dynamic programming solution for the unbounded knapsack decision problem be used to come up with a dynamic programming solution to the subset-sum decision problem? This limitation seems to render the unbounded knapsack problem useless. In the unbounded knapsack, we simply store true or false for if some subset of integers sum up to our target value. However, if we have a limit on the frequency of the use of these integers, the optimal substructure at least appears to fail. How can this be done?

    Read the article

  • PL/SQL Sum by hour

    - by Steve
    Hi, I have some data with start and stop date that I need to sum. I am not sure how to code for it. Here are is the data I have to use: STARTTIME,STOPTIME,EVENTCAPACITY 8/12/2009 1:15:00 PM,8/12/2009 1:59:59 PM,100 8/12/2009 2:00:00 PM,8/12/2009 2:29:59 PM,100 8/12/2009 2:30:00 PM,8/12/2009 2:59:59 PM,80 8/12/2009 3:00:00 PM,8/12/2009 3:59:59 PM,85 In this example I would need the sum from 1pm to 2pm, 2pm to 3pm and 3pm to 4pm Any suggestions are appreciated. Steve

    Read the article

  • MySQL SUM Query daily values of a week problem

    - by davykiash
    Am trying to return the sum of each day of a week in mysql but it returns nothing despite having values for the 3rd Week of March 2010 SELECT SUM(expense_details_amount) AS total FROM expense_details WHERE YEAR(expense_details_date) = '2010' AND MONTH(expense_details_date) = '03' AND WEEK(expense_details_date) = '3' GROUP BY DAY(expense_details_date) How do I go about this?

    Read the article

  • Django: Sum on an date attribute grouped by month/year

    - by Sébastien Piquemal
    Hello, I'd like to put this query from SQL to Django: "select date_format(date, '%Y-%m') as month, sum(quantity) as hours from hourentries group by date_format(date, '%Y-%m') order by date;" The part that causes problem is to group by month when aggregating. I tried this (which seemed logical), but it didn't work : HourEntries.objects.order_by("date").values("date__month").aggregate(Sum("quantity"))

    Read the article

  • sum of logarithams of prime numbers

    - by nadi
    Write a program that computes the sum of the logarithms of all the primes from 2 to some number n, and print out the sum of the logs of the primes, the number n, and the ratio of these two quantities. Test this for different values of n.

    Read the article

  • Generate 3 random number that sum to 1 in R

    - by user1034797
    I am hoping to create 3 (non-negative) quasi-random numbers that sum to one, and repeat over and over. Basically I am trying to partition something into three random parts over many trials. While I am aware of a= runif(3,0,1) I was thinking that I could use 1-a as the max in the next run if, but it seems messy. But these of course don't sum to one. Any thoughts, oh wise stackoverflow-ers?

    Read the article

  • calculate sum time with mysql

    - by kawtousse
    hi every one, RDBMS: mysql colonne names: Timefrom,timeuntill, timespent as the following type of the colonnes:Time. timefrom timeuntill timespent 10:00:00 12:00:00 02:00:00 08:00:00 09:00:00 01:00:00 how could i get the sum of the timespent. like this example it would be 03:00:00. when doing select sum(timespent) from mytable it display: 030000. please help. thanks.

    Read the article

  • faster implementation of sum ( for Codility test )

    - by Oscar Reyes
    How can the following simple implementation of sum be faster? private long sum( int [] a, int begin, int end ) { if( a == null ) { return 0; } long r = 0; for( int i = begin ; i < end ; i++ ) { r+= a[i]; } return r; } EDIT Background is in order. Reading latest entry on coding horror, I came to this site: http://codility.com which has this interesting programming test. Anyway, I got 60 out of 100 in my submission, and basically ( I think ) is because this implementation of sum, because those parts where I failed are the performance parts. I'm getting TIME_OUT_ERROR's So, I was wondering if an optimization in the algorithm is possible. So, no built in functions or assembly would be allowed. This my be done in C, C++, C#, Java or pretty much in any other. EDIT As usual, mmyers was right. I did profile the code and I saw most of the time was spent on that function, but I didn't understand why. So what I did was to throw away my implementation and start with a new one. This time I've got an optimal solution [ according to San Jacinto O(n) -see comments to MSN below - ] This time I've got 81% on Codility which I think is good enough. The problem is that I didn't take the 30 mins. but around 2 hrs. but I guess that leaves me still as a good programmer, for I could work on the problem until I found an optimal solution: Here's my result. I never understood what is those "combinations of..." nor how to test "extreme_first"

    Read the article

  • SQL using sum to count results of multiple subqueries

    - by asdas
    I have a table with 2 columns: integer and var char. I am given only the integer values but need to do work on the var char (string) values. Given an integer, and a list of other integers (no overlap), I want to find the string for that single integer. Then I want to take that string and do the INSTR command with that string, and all the other strings for all the other integers. Then I want the sum of all the INSTR so the result is one number. So lets say I have int x, and list y=[y0, y1, y2]. I want to do 3 INSTR commands like SUM(INSTR(string for x, string for y0), INSTR(string for x, string for y1), INSTR(string for x, string for y2)) I think im going in the wrong direction, this is what I have. Im not good with sub queries. SELECT SUM ( SELECT INSTR ( SELECT string FROM pages WHERE int=? LIMIT 1, ( SELECT string FROM pages WHERE id=? OR id=? OR id=? LIMIT 3 ) ) )

    Read the article

  • SELECT SUM PHP MySQL problem

    - by user345426
    This is driving me nuts! Below you will find my PHP/MySQL code but I will post the direct mySQL statement here: SELECT SUM( ot.value ) AS msa FROM orders o LEFT JOIN orders_total ot ON ot.orders_id = o.orders_id WHERE ot.class = 'ot_total' AND UNIX_TIMESTAMP( o.date_purchased ) >=1262332800 AND UNIX_TIMESTAMP( o.date_purchased ) <=1264924800 AND o.sales_rep_id = '2' When I execute this statement inside of phpMyAdmin I get the sum for ot.value which is associated to "msa". Although, when I run my php code it does not return a value. Anyone see the problem? // works in phpMyAdmin but not displaying during PHP execution! $monthly_sales_amount_sql = "SELECT SUM(ot.value) AS msa FROM orders o LEFT JOIN orders_total ot ON ot.orders_id = o.orders_id WHERE ot.class = 'ot_total' AND UNIX_TIMESTAMP(o.date_purchased) >= $start_timestamp AND UNIX_TIMESTAMP(o.date_purchased) <= $end_timestamp AND o.sales_rep_id = '" . $sales_rep_id "'"; $result = mysql_query($monthly_sales_amount_sql); $row = mysql_fetch_assoc($result); echo "MSA: " . $row['msa'] . "<BR><BR>";

    Read the article

  • Mixing together Connect by, inner join and sum with Oracle

    - by François
    Hey there, I need help with a oracle query. Excuse me in advance for my english. Here is my setup: I have 2 tables called respectively "tasks" and "timesheets". The "tasks" table is a recursive one, that way each task can have multiple subtasks. Each timesheet is associated with a task (not necessarily the "root" task) and contains the number of hours worked on it. Example: Tasks id:1 | name: Task A | parent_id: NULL id:2 | name: Task A1 | parent_id: 1 id:3 | name: Task A1.1 | parent_id: 2 id:4 | name: Task B | parent_id: NULL id:5 | name: Task B1 | parent_id: 4 Timesheets id:1 | task_id: 1 | hours: 1 id:2 | task_id: 2 | hours: 3 id:3 | task_id:3 | hours: 1 id:5 | task_id:5 | hours:1 ... What I want to do: I want a query that will return the sum of all the hours worked on a "task hierarchy". If we take a look at the previous example, It means I would like to have the following results: task A - 5 hour(s) | task B - 1 hour(s) At first I tried this SELECT TaskName, Sum(Hours) "TotalHours" FROM ( SELECT replace(sys_connect_by_path(decode(level, 1, t.name), '~'), '~') As TaskName, ts.hours as hours FROM tasks t INNER JOIN timesheets ts ON t.id=ts.task_id START WITH PARENTOID=-1 CONNECT BY PRIOR t.id = t.parent_id ) GROUP BY TaskName Having Sum(Hours) > 0 ORDER BY TaskName And it almost work. THe only problem is that if there are no timesheet for a root task, it will skip the whole hieararchy... but there might be timesheets for the child rows and it is exactly what happens with Task B1. I know it is the "inner join" part that is causing my problem but I'm not sure how can I get rid of it. Any idea how to solve this problem? Thank you

    Read the article

  • Join and sum not compatible matrices through data.table

    - by leodido
    My goal is to "sum" two not compatible matrices (matrices with different dimensions) using (and preserving) row and column names. I've figured this approach: convert the matrices to data.table objects, join them and then sum columns vectors. An example: > M1 1 3 4 5 7 8 1 0 0 1 0 0 0 3 0 0 0 0 0 0 4 1 0 0 0 0 0 5 0 0 0 0 0 0 7 0 0 0 0 1 0 8 0 0 0 0 0 0 > M2 1 3 4 5 8 1 0 0 1 0 0 3 0 0 0 0 0 4 1 0 0 0 0 5 0 0 0 0 0 8 0 0 0 0 0 > M1 %ms% M2 1 3 4 5 7 8 1 0 0 2 0 0 0 3 0 0 0 0 0 0 4 2 0 0 0 0 0 5 0 0 0 0 0 0 7 0 0 0 0 1 0 8 0 0 0 0 0 0 This is my code: M1 <- matrix(c(0,0,1,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0), byrow = TRUE, ncol = 6) colnames(M1) <- c(1,3,4,5,7,8) M2 <- matrix(c(0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0), byrow = TRUE, ncol = 5) colnames(M2) <- c(1,3,4,5,8) # to data.table objects DT1 <- data.table(M1, keep.rownames = TRUE, key = "rn") DT2 <- data.table(M2, keep.rownames = TRUE, key = "rn") # join and sum of common columns if (nrow(DT1) > nrow(DT2)) { A <- DT2[DT1, roll = TRUE] A[, list(X1 = X1 + X1.1, X3 = X3 + X3.1, X4 = X4 + X4.1, X5 = X5 + X5.1, X7, X8 = X8 + X8.1), by = rn] } That outputs: rn X1 X3 X4 X5 X7 X8 1: 1 0 0 2 0 0 0 2: 3 0 0 0 0 0 0 3: 4 2 0 0 0 0 0 4: 5 0 0 0 0 0 0 5: 7 0 0 0 0 1 0 6: 8 0 0 0 0 0 0 Then I can convert back this data.table to a matrix and fix row and column names. The questions are: how to generalize this procedure? I need a way to automatically create list(X1 = X1 + X1.1, X3 = X3 + X3.1, X4 = X4 + X4.1, X5 = X5 + X5.1, X7, X8 = X8 + X8.1) because i want to apply this function to matrices which dimensions (and row/columns names) are not known in advance. In summary I need a merge procedure that behaves as described. there are other strategies/implementations that achieve the same goal that are, at the same time, faster and generalized? (hoping that some data.table monster help me) to what kind of join (inner, outer, etc. etc.) is assimilable this procedure? Thanks in advance. p.s.: I'm using data.table version 1.8.2 EDIT - SOLUTIONS @Aaron solution. No external libraries, only base R. It works also on list of matrices. add_matrices_1 <- function(...) { a <- list(...) cols <- sort(unique(unlist(lapply(a, colnames)))) rows <- sort(unique(unlist(lapply(a, rownames)))) out <- array(0, dim = c(length(rows), length(cols)), dimnames = list(rows,cols)) for (m in a) out[rownames(m), colnames(m)] <- out[rownames(m), colnames(m)] + m out } @MadScone solution. Used reshape2 package. It works only on two matrices per call. add_matrices_2 <- function(m1, m2) { m <- acast(rbind(melt(M1), melt(M2)), Var1~Var2, fun.aggregate = sum) mn <- unique(colnames(m1), colnames(m2)) rownames(m) <- mn colnames(m) <- mn m } BENCHMARK (100 runs with microbenchmark package) Unit: microseconds expr min lq median uq max 1 add_matrices_1 196.009 257.5865 282.027 291.2735 549.397 2 add_matrices_2 13737.851 14697.9790 14864.778 16285.7650 25567.448 No need to comment the benchmark: @Aaron solution wins. I'll continue to investigate a similar solution for data.table objects. I'll add other solutions eventually reported or discovered.

    Read the article

  • Mysql join two tables and add column values

    - by Mike
    My knowledge of mysql is not very in depth. If I have two tables that for example look like this: Table1 Date v1 v2 v3 05/01/2010 26 abc 45 05/02/2010 31 def 25 05/03/2010 50 ghi 46 Table2 Date v1 v2 v3 05/01/2010 42 jkl 15 05/02/2010 28 mno 14 05/03/2010 12 pqr 64 How can I join them in a query by their date and have the sum of table1.v1 and table2.v1 and also have the sum of table1.v3 and table2.v3. V2 should be ignored.

    Read the article

  • "Invalid Column Name" error thrown by Access Reports?

    - by badpanda
    I am attempting to sum over a detail grouping on a specific field in Microsoft Access, and assign that sum to a field in the general grouping. When I try to run the report, I get an "Invalid Column Name" error with the detail field getting the error. Has anyone previously encountered this? If so, any ideas what might be causing it or how to solve it?

    Read the article

  • SQL - Add up all row-values of one column in a singletable

    - by ThE_-_BliZZarD
    Hello Everybody, I've got a question regarding a SQL-select-query: The table contains several columns, one of which is an Integer-column called "size" - the task I'm trying to perform is query the table for the sum of all rows (their values), or to be more exact get a artifical column in my ResultSet called "overallSize" which contains the sum of all "size"-values in the table. Preferable it would be possible to use a WHERE-clause to add only certain values ("WHERE bla = 5" or something similar). The DB-engine is HSQLDB (HyperSQL), which is compliant to SQL2008. Thank you in advance :)

    Read the article

  • In Excel how can I sum all the numbers above the current cell?

    - by Mark Meuer
    I want to have a column in Excel that consists of a header, a bunch of numbers, and then have the sum of those numbers at the bottom. I'd like the sum to adapt to the insertion of new numbers above the total. Something like this: Numbers 1 2 5 10 18 Total If I later insert 10 new numbers in the middle of the list, I want the sum to automatically include them. I know the SUM() function can sum a whole column, but if the total is also in that column then it complains about a circular reference. How can I just sum the numbers above the total?

    Read the article

  • LinQ to objects GroupBy() by object and Sum() by amount

    - by Daniil Harik
    Hello, I have pretty simple case which I started solving using foreach(), but then I thought I could do It using Linq Basically I have IList that contains PaymentTransaction objects and there are 2 properties Dealer and Amount I want to GroupBy() by Dealer and Sum() bv amount. I tried to accomplish this using following code, but unfortunately it does not work var test = paymentTransactionDao.GetAll().GroupBy(x => x.Dealer).Sum(x => x.Amount); Want exactly I'm doing wrong here? I'm sorry if this question is too simple. Thank You

    Read the article

  • How to use sum and count functions

    - by Odette
    hi guys I am trying to get the total count and total sum per salesperson but its not working in my WITH query Currently I have: WITH CALC1 AS (SELECT B.OTSMAN AS SALESMAN, COUNT(B.ONINUM) AS COUNT, SUM(B.OVSVAL) AS SVAL FROM @[email protected] AS B WHERE B.OCSGRP <> 'INT' AND B.OCSGRP <> 'INX' AND B.OCPSBR IN (@OCPSBR@) AND B.ICMATX <> '705' AND B.OCSGRP NOT LIKE 'S/%' GROUP BY B.OTSMAN, B.ONINUM ORDER BY B.OTSMAN ASC) SELECT SALESMAN, COUNT, SVAL FROM CALC1 ORDER BY SALESMAN THE RESULT IS: AM 1 79.03 AM 40 1337.70 AM 48 4627.15 AM 42 2727.40 AM 1 111.79 AM 1 1110.00 AM 52 3018.77 How do i change my query so I only get one record with the total count and value per salesperson? AM 1 13,011.84

    Read the article

  • Sum of Fibonacci numbers

    - by Rafal
    Hi, I'm rather new to Haskell. The problem is to find the sum of all even Fibonacci numbers not greater than 4 million. I can't use lists. If I understand correctly, the below solution is wrong, because it uses lists: my_sum = sum $ filter (even) $ takeWhile (< 4000000) fibs Where fibs is the list of all Fibonacci numbers. Somehow, I find it difficult not to think in Haskell in terms of lists. Could anyone guide me to a solution to this problem? Regards

    Read the article

  • How to make a sum of total for each id

    - by JetJack
    Using Crystal report 7 I want to view the table 1 and sum of table2 table1 id name 001 raja 002 vijay 003 suresh .... table2 id value 001 100 001 200 001 150 002 200 003 150 003 200 ... I want to display all the rows from table1 and sum(values) from table2. How to do this in crystal report Expected Output id name value 001 raja 450 002 vijay 200 003 suresh 350 .... Note: I add the table field directly to the report, i am not added store procedure or views or query in the report. How to do this. Need Crystal report help

    Read the article

  • Sum value of XML attributes using PowerShell 2.0

    - by Yooakim
    I have a directory with XML files. I quickly want to go through them and sum upp the value stored in one attribute. I have figured out how to fidn the nodes I am interested in. For example: (Select-Xml -Path .\*.xml -XPath "//*[@Attribue = 'valueImlookingfor']").Count This command gives me the count of elements in all of the XML files in the current directory which has the value "valueImlookingfor" in the "Attribue". I want to sum up all the values of the "Attribute", not count them. What would be the best way to do this in PowerShell? I am new to PowerShell so this may be trivial but un-known to me... All tips are much appreciated :-)

    Read the article

< Previous Page | 3 4 5 6 7 8 9 10 11 12 13 14  | Next Page >