Search Results

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

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

  • Modify a given number to find the required sum?

    - by Gaurav
    A friend of mine sent me this question. I haven't really been able to come up with any kind of algorithm to solve this problem. You are provided with a no. say 123456789 and two operators * and +. Now without changing the sequence of the provided no. and using these operators as many times as you wish, evaluate the given value: eg: given value 2097 Solution: 1+2+345*6+7+8+9 Any ideas on how to approach problems like these?

    Read the article

  • I can't Distinct, Sum, or Count from 3 tables with group clauses

    - by Rio Inggit Dharmawangsa
    I'm still learning linq, now i'm getting confused. I need data for report from 3 tables, I get the result, but it's duplicate. I have used distinct but it's not working, n I need data to be sum still not working. Here is my query, can somebody explain what's wrong? var report= (from u in myDb.TBL_TRANSAKSI_MKN_MNMs.AsEnumerable() where u.TGL_TRANSAKSI.Value.Date.Equals(dateTimePicker1.Value.Date) join l in myDb.TBL_DETAIL_TRANSAKSIs.AsEnumerable() on u.ID_NOTA equals l.ID_NOTA join m in myDb.TBL_MKN_MNMs.AsEnumerable() on l.ID_MKN_MNM equals m.ID_MKN_MNM group new { u, l, m } by new { m.NAMA_MKN_MNM, m.HARGA_JUAL, u.TGL_TRANSAKSI, l.ID_MKN_MNM, u.USERNAME, l.Jumlah } into grp select new { MakanMinum = grp.Key.NAMA_MKN_MNM, HargaJual = grp.Key.HARGA_JUAL, Stok = grp.Sum(groupedthing => groupedthing.l.Jumlah), Tanggal = grp.Key.TGL_TRANSAKSI, Jumlah =(grp.Key.HARGA_JUAL * grp.Sum(groupedthing => groupedthing.l.Jumlah)), Total = grp.Sum(grouptotal => grp.Key.HARGA_JUAL * grp.Sum(groupedthing => groupedthing.l.Jumlah)), Username = grp.Key.USERNAME }).Distinct();

    Read the article

  • sumList predicate needs to check to see if their Sum is equal to the sum of all the elements in the list

    - by nick bonnet
    I am implementing a method that when given Sum and a List. It will check to see that if you add the elements in the list, their sum is equal to the Sum given. Here is what I am trying to do thus far, but I am pretty sure it is wrong... I'm not really sure how to think about it. sumList([],0). sumList([X|Xrest], Sum) :- sumList[Xrest, Sum1), Sum is X + Sum1. Could you give me a point in the right direction or at least let me know how to try to think about the problem?

    Read the article

  • Addind the sum of numbers using a loop statement

    - by Deonna
    I need serious help diving the positive numbers and the negative numbers. I am to accumulate the total of the negative values and separately accumulate the total of the positive values. After the loop, you are then to display the sum of the negative values and the sum of the positive values. The data is suppose to look like this: -2.3 -1.9 -1.5 -1.1 -0.7 -0.3 0.1 0.5 0.9 1.3 1.7 2.1 2.5 2.9 Sum of negative values: -7.8 Sum of positive values: 12 So far I have this: int main () { int num, num2, num3, num4, num5, sum, count, sum1; int tempVariable = 0; int numCount = 100; int newlineCount = 0, newlineCount1 = 0; float numCount1 = -2.3; while (numCount <= 150) { cout << numCount << " "; numCount += 2; newlineCount ++; if(newlineCount == 6) { cout<< " " << endl; newlineCount = 0; } } **cout << "" << endl; while (numCount1 <=2.9 ) { cout << numCount1 << " "; numCount1 += 0.4; newlineCount1 ++; } while ( newlineCount1 <= 0 && newlineCount >= -2.3 ); cout << "The sum is " << newlineCount1 << endl;** return 0; }

    Read the article

  • Adding the sum of numbers using a loop statement

    - by Deonna
    I need serious help dividing the positive numbers and the negative numbers. I am to accumulate the total of the negative values and separately accumulate the total of the positive values. After the loop, you are then to display the sum of the negative values and the sum of the positive values. The data is suppose to look like this: -2.3 -1.9 -1.5 -1.1 -0.7 -0.3 0.1 0.5 0.9 1.3 1.7 2.1 2.5 2.9 Sum of negative values: -7.8 Sum of positive values: 12 So far I have this: int main () { int num, num2, num3, num4, num5, sum, count, sum1; int tempVariable = 0; int numCount = 100; int newlineCount = 0, newlineCount1 = 0; float numCount1 = -2.3; while (numCount <= 150) { cout << numCount << " "; numCount += 2; newlineCount ++; if(newlineCount == 6) { cout<< " " << endl; newlineCount = 0; } } **cout << "" << endl; while (numCount1 <=2.9 ) { cout << numCount1 << " "; numCount1 += 0.4; newlineCount1 ++; } while ( newlineCount1 <= 0 && newlineCount >= -2.3 ); cout << "The sum is " << newlineCount1 << endl;** return 0; }

    Read the article

  • Sum of two Textbox values into third Textbox using JQuery

    - by Rajneesh Verma
    A script that sums up two textbox values using jQuery. **Note that I am not using any validation for textbox values. <html xmlns= "http://www.w3.org/1999/xhtml" > <head runat= "server" > <title></title> <script type= "text/javascript" src= "http://ajax.googleapis.com/ajax/libs/jquery/1.4.4/jquery.min.js" ></script> <script type= "text/javascript" > $(function () { var textBox1 = $( 'input:text[id$=TextBox1...(read more)

    Read the article

  • XQuery method question, trying to sum values read from xml

    - by Buck
    I'm pretty new to XQuery and I'm trying to write an example function that I can't get to work. I want to read an xml file, parse out the "time" values, sum them as they're read and return the sum. This is trivial and I'm looking to build more functionality into it but I'd like to get this working first. Also, I know there's a "sum" directive in XQuery that would do just this but I want to add more to it so the built-in sum is insufficient for my needs. Here's my funtion: bool example(Zorba* aZorba) { XQuery_t lQuery = aZorba-compileQuery( "for $i in fn:doc('/tmp/products.xml')//time" "let $sum := xs:integer($i)" " return $sum" ); DynamicContext* lCtx = lQuery-getDynamicContext(); lCtx-setContextItemAsDocument("temp_measurements.xml", lDocStream); try { std::cout << lQuery << std::endl; } catch (DynamicException& e) { std::cerr << e.getDescription() << std::endl; return false; } catch (StaticException& f){ std::cerr << f.getDescription() << f.getErrorCodeAsString(f.getErrorCode()) << std::endl; return false; } } It's called with an appropriate main(). If I comment out the line that starts "let $sum..." then this works in that it returns the time values as a series of integers like this: 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 3 3 3 3 3 3 3 3 3.... Input file looks like this: <?xml version="1.0" encoding="UTF-8"? <temps <temp <time0</time <lat0</lat <long0</long <value0</value </temp <temp <time1</time <lat0</lat <long1</long <value0</value </temp ...

    Read the article

  • Help! I'm a Haskell Newbie

    - by Darknight
    I've only just dipped my toe in the world of Haskell as part of my journey of programming enlightenment (moving on from, procedural to OOP to concurrent to now functional). I've been trying an online Haskell Evaluator. However I'm now stuck on a problem: Create a simple function that gives the total sum of an array of numbers. In a procedural language this for me is easy enough (using recursion) (c#) : private int sum(ArrayList x, int i) { if (!(x.Count < i + 1)) { int t = 0; t = x.Item(i); t = sum(x, i + 1) + t; return t; } } All very fine however my failed attempt at Haskell was thus: let sum x = x+sum in map sum [1..10] this resulted in the following error (from that above mentioned website): Occurs check: cannot construct the infinite type: a = a -> t Please bear in mind I've only used Haskell for the last 30 minutes! I'm not looking simply for an answer but a more explanation of it. Thanks in advanced.

    Read the article

  • SSRS sum(distinct()) equivalent

    - by HurnsMobile
    I am currently working with an SSRS 2008 report that returns a dataset similar to the following: Job# ClientId MoneyIn MoneyOut ------------------------------ 1 ABC123 10 25 1 ABC123 10 25 1 ABC123 5 25 2 XYZ123 25 50 2 XYZ123 25 50 3 XYZ123 15 15 Where MoneyOut should be equal to the total amount of MoneyIn for a job if the job has been balanced out correctly. The problem that I am running into is when displaying this in a tablix in SSRS I can return the correct MoneyOut value for a job by setting the field to =first(Fields!MoneyOut.Value) but I also need to sum the value of these by day and attempting to do =sum(first(Fields!MoneyOut.Value)) yields an error about nesting aggregate functions. I've also attempted to sum the value of the textboxes using something like =sum(ReportItems!MoneyOut1.Value) which yields an error that you can only use aggregates on report items in the header or footer. So my question is, is there some way to duplicate the functionality of distinct() in SSRS reports or is there some way to just total up the values of text fields that I am unaware of? Thanks in advance, TJ

    Read the article

  • Django select distinct sum

    - by yoshi
    I have the following (greatly simplified) table structure: Order: order_number = CharField order_invoice_number = CharField order_invoice_value = CharField An invoice number can be identical on more than one order (order O1 has invoice number I1, order O2 has invoice number I1, etc.). All the orders with the same invoice number have the same invoice value. For example: Order no. Invoice no. Value O1 I1 200 O2 I1 200 O3 I1 200 04 I2 50 05 I2 100 What I am trying to do is do a sum over all the invoice values, but don't add the invoices with the same number more than once. The sum for the above items would be: 200+50+100. I tried doing this using s = orders.values('order_invoice_id').annotate(total=Sum('order_invoice_value')).order_by() and s = orders.values('order_invoice_id').order_by().annotate(total=Sum('order_invoice_value')) but I didn't get the desired result. I tried a few different solutions from similar questions around here but I couldn't get the desired result. I can't figure out what I'm doing wrong and what I actually should do to get a sum that uses each invoice value just once.

    Read the article

  • sql sum data from multiple tables

    - by Iulian
    I have 2 tables AP and INV where both have the columns [PROJECT] and [Value]. I want a query to return something like this : PROJECT | SUM_AP | SUM_INV I came up with the code below but it's returning the wrong results ( sum is wrong ). SELECT SUM(AP.Value) AS SUM_AP, SUM(INV.Value) AS SUM_INV FROM AP INNER JOIN INV ON (AP.[PROJECT] =INV.[PROJECT]) WHERE AP.[PROJECT] = 'XXXXX' GROUP BY AP.[PROJECT]

    Read the article

  • MySQL query, SUM of multiple colums

    - by Mick
    Hi I have multiple columns in a mySQL table. Three of the columns are named i100s, i60s and i25s and what I want to do is get the sum of all three entries . currently I have this code '$query= "SELECT SUM(i100s),SUM(i60s),SUM(i25s) AS tkit FROM event WHERE acc='100' " ; $result = mysql_query($query) or die(mysql_error()); $row = mysql_fetch_assoc($result) ; $total = $row['tkit'];' But it is not returning the correct result , can anyone help me please ? Thanks Mick

    Read the article

  • How to get rank based on SUM's?

    - by Kenan
    I have comments table where everything is stored, and i have to SUM everything and add BEST ANSWER*10. I need rank for whole list, and how to show rank for specified user/ID. Here is the SQL: SELECT m.member_id AS member_id, (SUM(c.vote_value) + SUM(c.best)*10) AS total FROM comments c LEFT JOIN members m ON c.author_id = m.member_id GROUP BY c.author_id ORDER BY total DESC LIMIT {$sql_start}, 20

    Read the article

  • How to Sum calulated fields

    - by Nazero Jerry
    I‘d like to ask I question that here that I think would be easy to some people. Ok I have query that return records of two related tables. (One to many) In this query I have about 3 to 4 calculated fields that are based on the fields from the 2 tables. Now I want to have a group by clause for names and sum clause to sum the calculated fields but it ends up in error message saying: “You tried to execute a query that is not part of aggregate function” So I decided to just run the query without the totals *(ie no group by , sum etc,,,) : And then I created another query that totals my previous query. ( i.e. using group by clause for names and sum for calculated fields… no calculation here) This is fine ( I use to do this) but I don’t like having two queries just to get summary total. Is their any other way of doing this in the design view and create only one query?. I would very much appreciate. Thankyou: JM

    Read the article

  • Sum function doesn't work :/

    - by StackedCrooked
    A while ago this code seemed to work, but now it doesn't anymore. Is there something wrong with it? user=> (defn sum [a b] (a + b)) #'user/sum user=> (sum 3 4) java.lang.ClassCastException: java.lang.Integer cannot be cast to clojure.lang.IFn (NO_SOURCE_FILE:0) user=> It's probably time to take a break :)

    Read the article

  • Sum values in a DataTable by a given criteria

    - by šljaker
    Which is the most effective way to sum data in the DataTable by a given criteria? I have the following table: KEY_1 KEY_2, VALUE_1, VALUE_2 Input: 01101, P, 2, 3 01101, F, 1, 1 01101, P, 4, 4 10102, F, 5, 7 Desired output (new DataTable): 01101, P, 6, 7 01101, F, 1, 1 01101, SUM, 7, 8 10102, F, 5, 7 10102, SUM, 5, 7 I need efficient algorithm, because I have 10k rows and 18 columns in a DataTable. Thank you.

    Read the article

  • Linq TakeWhile depending on sum (or aggregate) of elements

    - by martinweser
    I have a list of elements and want to takeWhile the sum (or any aggregation of the elements) satisfy a certain condition. The following code does the job, but i am pretty sure this is not an unusual problem for which a proper pattern should exist. var list = new List<int> { 1, 2, 3, 4, 5, 6, 7 }; int tmp = 0; var listWithSum = from x in list let sum = tmp+=x select new {x, sum}; int MAX = 10; var result = from x in listWithSum where x.sum < MAX select x.x; Does somebody know how to solve the task in nicer way, probably combining TakeWhile and Aggregate into one query? Thx

    Read the article

  • Linq Having Sum(Quantity) = x?

    - by molgan
    Hello I have a function that returns IQueryable, and I would like to add "HAVING SUM(Quantity) = X" to it, but I get error if I try like this: _rep.GetBookings().ByBookingObjectID(bookingObjectID).Sum(x => x.Quantity == somevariablehere); I cant seem to find functions for it to find by sum /M

    Read the article

  • Average of a Sum in Mysql query

    - by chupeman
    I am having some problems creating a query that gives me the average of a sum. I read a few examples here in stackoverflow and couldn't do it. Can anyone help me to understand how to do this please? This is the data I have: Basically I need the average transaction value by cashier. I can't run a basic avg because it will take all rows but each transaction can have multiple rows. At the end I want to have: Cashier| Average| 131 | 44.31 |(Which comes from the sum divided by 3 transactions not 5 rows) 130 | 33.15 | etc. This is the query I have to SUM the transactions but don't know how or where to include the AVG function. SELECT `products`.`Transaction_x0020_Number`, Sum(`products`.`Sales_x0020_Value`) AS `SUM of Sales_x0020_Value`, `products`.`Cashier` FROM `products` GROUP BY `products`.`Transaction_x0020_Number`, `products`.`Date`, `products`.`Cashier` HAVING (`products`.`Date` ={d'2010-06-04'}) Any help is appreciated.

    Read the article

  • Redundancy in doing sum()

    - by Abhi
    table1 - id, time_stamp, value This table consists of 10 id's. Each id would be having a value for each hour in a day. So for 1 day, there would be 240 records in this table. table2 - id Table2 consists of a dynamically changing subset of id's present in table1. At a particular instance, the intention is to get sum(value) from table1, considering id's only in table2, grouping by each hour in that day, giving the summarized values a rank and repeating this each day. the query is at this stage: select time_stamp, sum(value), rank() over (partition by trunc(time_stamp) order by sum(value) desc) rn from table1 where exists (select t2.id from table2 t2 where id=t2.id) and time_stamp >= to_date('05/04/2010 00','dd/mm/yyyy hh24') and time_stamp <= to_date('25/04/2010 23','dd/mm/yyyy hh24') group by time_stamp order by time_stamp asc If the query is correct, can this be made more efficient, considering that, table1 will actually consist of thousand's of id's instead of 10 ? EDIT: I am using sum(value) 2 times in the query, which I am not able to get a workaround such that the sum() is done only once. Pls help on this

    Read the article

  • Occasional conversion error using SUM function

    - by user153777
    My app uses sql2000 and a select statement it uses will sometimes fail. Once a week or so the select returns the error 'Error Converting data type varchar to numeric' SQL: sum(case when ISNULL(form_prsn_id, -1) = irpd_prsn_id then convert(dec(11,2), case when valu_value = '' then '0' else isnull (valu_value,'0') end)* case when fmdt_deduction_flag = 'Y' then -1 else 1 end else 0 end) as client_sum The valu_value field is a varchar and stores some numeric and some varchar. But including my join and where clause filter it will always select numeric or empty string. When it is failing I can remove the SUM, see the data and know that its numeric. So why would the SUM function sometimes (say 5% of time) fail on data that is numeric. I wonder if SQL somehow "looks ahead" to ensure it could convert to decimal on more than just the rows returned without the sum. Note I have discovered a fix where I include ( where isNumeric(valu_value) = 1 ) Thanks

    Read the article

  • EF Linq Product Sum when no records returned

    - by user1622713
    I’ve seen variations of this question all over the place but none of the answers work for me. Most of them are just trying to sum a single column too – nothing more complex such as the sum of a product as below: public double Total { get { return _Context.Sales.Where(t => t.Quantity > 0) .DefaultIfEmpty() .Sum(t => t.Quantity * t.Price); } } If no rows are returned I want to return zero. However if no rows are returned the .Sum() fails. There are various options of trying to insert Convert.ToDouble and using null coalesce operators, but they all still gave me errors. I’m sure I am missing a simple way to do this – any help greatly appreciated after too long banging head against google brick wall!

    Read the article

  • Doing sum's if certain conditions are true

    - by Gugu
    I am trying to build a query that does a sum if a certain parameter is set. For example: SELECT SUM(IF(<condition>,field,field)) AS total_value ...which is working correctly. But i have more than one condition in IF(), like: SELECT SUM(IF(<condition> <condition>,field,field)) AS total_value ..which is not working, could you have any idea what should be the right query for this.

    Read the article

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