Search Results

Search found 3047 results on 122 pages for 'subset sum'.

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

  • I can't make this query work with SUM function

    - by Mehper C. Palavuzlar
    This query gives an error: select ep, case when ob is null and b2b_ob is null then 'a' when ob is not null or b2b_ob is not null then 'b' else null end as type, sum(b2b_d + b2b_t - b2b_i) as sales from table where ... group by ep, type Error: ORA-00904: "TYPE": invalid identifier When I run it with group by ep, the error message becomes: ORA-00979: not a GROUP BY expression The whole query works OK if I remove the lines sum(b2b_d+b2b_t-b2b_i) as sales and group by ..., so the problem should be related to SUM and GROUP BY functions. How can I make this work? Thanks in advance for your help.

    Read the article

  • SELECT SUM returns a row when there are no records

    - by Jose L Martinez-Avial
    Hi, I'm finding some problems with a query that returns the sum of a field from a table for all the records that meet certain conditions. I expected to receive a "No records found' when there were no records, but instead I'm receiving a null result. SQL> SELECT * FROM DUAL WHERE 1=2; no rows selected SQL> SELECT SUM(dummy) FROM DUAL WHERE 1=2; SUM(DUMMY) ---------- SQL> Is there any way to not receive any record in that case?

    Read the article

  • Changing a SUM returned NULL to zero

    - by Lee_McIntosh
    I have a Stored Procedure as follows: CREATE PROC [dbo].[Incidents] (@SiteName varchar(200)) AS SELECT ( SELECT SUM(i.Logged) FROM tbl_Sites s INNER JOIN tbl_Incidents i ON s.Location = i.Location WHERE s.Sites = @SiteName AND i.[month] = DATEADD(mm, DATEDIFF(mm, 0, GetDate()) -1,0) GROUP BY s.Sites ) AS LoggedIncidents 'tbl_Sites contains a list of reported on sites. 'tbl_Incidents containts a generated list of total incidents by site/date (monthly) 'If a site doesnt have any incidents that month it wont be listed. The problem I'm having is that a site doesnt have any Incidents this month and as such i get a NULL value returned for that site when i run this sproc, but i need to have a zero/0 returned to be used within a chart in SSRS. I've tried the using coalesce and isnull to no avail. SELECT COALESCE(SUM(c.Logged,0)) SELECT SUM(ISNULL(c.Logged,0)) Is there a way to get this formatted correctly? Cheers, Lee

    Read the article

  • Complex Join - involving date ranges and sum...

    - by calumbrodie
    I have two tables that I need to join... I want to join table1 and table2 on 'id' - however in table two id is not unique. I only want one value returned for table two, and this value represents the sum of a column called 'total_sold' - within a specified date range (say one month).. SELECT ta.id, tb.total_sold as total_sold_this_week FROM table_a as ta LEFT JOIN table_b as tb ON ta.id=tb.id AND tb.date_sold BETWEEN ADDDATE(NOW(),INTERVAL -3 WEEK) AND NOW() this works but does not SUM the rows - only returning one row for each id... how do I get the sum from table b instead of only one row??? Please criticise if format of question could use more work - I can rewrite and provide sample data if required - this is a trivialised version of a much larger problem. -Thanks

    Read the article

  • MYSQL sum() for distinct rows

    - by makeee
    I'm looking for help using sum() in my SQL query (not posting full query since the scenario is fairly simple). I have COUNT(DISTINCT conversions.id) in my query. I use DISTINCT because I'm doing "group by" for multiple columns and this ensures the same row is not counted more than once. Now I want to add: SUM(conversions.value) as conversion_value The problem is that the "value" for each row is counted more than once (due to the multiple group bys) I basically want to do SUM(conversions.value) for each DISTINCT conversions.id. Is that possible?

    Read the article

  • subset a data.frame with multiple conditions

    - by pslice
    Suppose my data looks like this: 2372 Kansas KS2000111 HUMBOLDT, CITY OF ATRAZINE 1.3 05/07/2006 9104 Kansas KS2000111 HUMBOLDT, CITY OF ATRAZINE 0.34 07/23/2006 9212 Kansas KS2000111 HUMBOLDT, CITY OF ATRAZINE 0.33 02/11/2007 2094 Kansas KS2000111 HUMBOLDT, CITY OF ATRAZINE 1.4 05/06/2007 16763 Kansas KS2000111 HUMBOLDT, CITY OF ATRAZINE 0.61 05/11/2009 1076 Kansas KS2000111 HUMBOLDT, CITY OF METOLACHLOR 0.48 05/12/2002 1077 Kansas KS2000111 HUMBOLDT, CITY OF METOLACHLOR 0.3 05/07/2006 I want to be able to subset by the Analyte and a partial match on the date(namely I just want the year). I have been trying this, but I know it isn't quite right. data[data$Analyte=="ATRAZINE" & grep("2006",as.character(data$Date)),] Any suggestions?

    Read the article

  • What is the better approach to find if a given set is a perfect subset of a set - If given subset is

    - by Microkernel
    Hi guys, What is the best approach to find if a given set(unsorted) is a perfect subset of a main set. I got to do some validation in my program where I got to compare the clients request set with the registered internal capability set. I thought of doing by having internal capability set sorted(will not change once registered) and do Binary search for each element in the client's request set. Is it the best I could get? I suspected that there might be better approach. Any idea? Regards, Microkernel

    Read the article

  • Subset generation by rules

    - by Sazug
    Let's say that we have a 5000 users in database. User row has sex column, place where he/she was born column and status (married or not married) column. How to generate a random subset (let's say 100 users) that would satisfy these conditions: 40% should be males and 60% - females 50% should be born in USA, 20% born in UK, 20% born in Canada, 10% in Australia 70% should be married and 30% not. These conditions are independent, that is we cannot do like this: (0.4 * 0.5 * 0.7) * 100 = 14 users that are males, born in USA and married (0.4 * 0.5 * 0.3) * 100 = 6 users that are males, born in USA and not married. Is there an algorithm to this generation?

    Read the article

  • Cocoa @sum array operator too slow - alternatives?

    - by icodestuff
    I've got a text field value bound to a key path that uses @sum. When the array controller is filtered, the text field updates properly, but extremely slowly, lagging the UI or outright beachballing after every key press (less so as the number of items in arrangedObjects decreases). There is no lag if I don't use @sum; I've narrowed it down to this. Is there a faster way to do the same thing?

    Read the article

  • SQL Update to the SUM if it's joined values

    - by CL4NCY
    Hi, I'm trying to update a field in the database to the sum of it's joined values: UPDATE P SET extrasPrice = SUM(E.price) FROM dbo.BookingPitchExtras AS E INNER JOIN dbo.BookingPitches AS P ON E.pitchID = P.ID AND P.bookingID = 1 WHERE E.[required] = 1 When I run this I get the following error: "An aggregate may not appear in the set list of an UPDATE statement." Any ideas?

    Read the article

  • SQL Update to the SUM of its joined values

    - by CL4NCY
    Hi, I'm trying to update a field in the database to the sum of its joined values: UPDATE P SET extrasPrice = SUM(E.price) FROM dbo.BookingPitchExtras AS E INNER JOIN dbo.BookingPitches AS P ON E.pitchID = P.ID AND P.bookingID = 1 WHERE E.[required] = 1 When I run this I get the following error: "An aggregate may not appear in the set list of an UPDATE statement." Any ideas?

    Read the article

  • Getting N random numbers that the sum is M

    - by marionmaiden
    Hello I want to get N random numbers that the sum of them is a value. For example, let's suppose I want 5 random numbers that their sum is 1 Then, a valid possibility is: 0.2 0.2 0.2 0.2 0.2 Other possibility is: 0.8 0.1 0.03 0.03 0.04 And so on. I need this for the creation of the matrix of belongings of the Fuzzy C-means.

    Read the article

  • Best way to score and sum in Scala?

    - by adam77
    Is there a better way of doing this: val totalScore = set.foldLeft(0)( _ + score(_) ) or this: val totalScore = set.map(score(_)).sum I think it's quite a common operation so was expecting something sleeker like: val totalScore = set.sum( score(_) )

    Read the article

  • Sum an Array - Objective-C

    - by Graham
    Hi Guys, I'm just starting out and I'm looking for an easy way to sum a simple array. I've read into apple developer site on key value coding and I don't understand how to apply that to my array or if that's the appropriate way to sum this. My stumbling block with the key value coding is the .keypathToProperty - I can sort of understand that you need a further reference in a 2D array but they don't show the array code, only the keypath to the title of the row so I can't figure it out yet. NSMutableArray *numArray = [NSMutableArray arrayWithCapacity:4]; [numArray addObject:num1]; [numArray addObject:num2]; [numArray addObject:num3]; [numArray addObject:num4]; I appreciate the replies! Thanks Graham

    Read the article

  • Generating Running Sum of Ratings in SQL

    - by Koobz
    I have a rating table. It boils down to: rating_value created +2 april 3rd -5 april 20th So, every time someone gets rated, I track that rating event in the database. I want to generate a rating history/time graph where the rating is the sum of all ratings up to that point in time on a graph. I.E. A person's rating on April 5th might be select sum(rating_value) from ratings where created <= april 5th The only problem with this approach is I have to run this day by day across the interval I'm interested in. Is there some trick to generating a running total using this sort of data? Otherwise, I'm thinking the best approach is to create a denormalized "rating history" table alongside the individual ratings.

    Read the article

  • MySQL count/sum fields

    - by Conor H
    Hi There, What I am trying to achieve is a report on daily financial transactions. With my SQL query I would like to count the total number of cash transactions, the total cash value and the same for checks. I only want to do this for a specified date. Here is a snippet of the query that I am having trouble with. These sum and count commands are processing all the data in the table and not for the selected date. (SELECT SUM(amount) FROM TRANSACTION WHERE payment_type.name = 'cash') AS total_cash, (SELECT COUNT(*) FROM TRANSACTION WHERE payment_type.name = 'cash') AS total_cash_transactions Sorry if I havent posted enough detail as I haven't time. If you need more info just ask.. Cheers.

    Read the article

  • ruby: sum corresponding members of two arrays

    - by jjnevis
    I've got two (or more) arrays with 12 integers in each (corresponding to values for each month). All I want is to add them together so that I've got a single array with summed values for each month. Here's an example with three values: [1,2,3] and [4,5,6] = [5,7,9] The best I could come up with was: [[1,2,3],[4,5,6]].transpose.map{|arr| arr.inject{|sum, element| sum+element}} #=> [5,7,9] Is there a better way of doing this? It just seems such a basic thing to want to do.

    Read the article

  • SUM a pair of COUNTs from two tables based on a time variable

    - by Kevin O.
    Been searching for an answer to this for the better part of an hour without much luck. I have two regional tables laid out with the same column names and I can put out a result list for either table based on the following query (swap Table2 for Table1): SELECT Table1.YEAR, FORMAT(COUNT(Table1.id),0) AS Total FROM Table1 WHERE Table1.variable='Y' GROUP BY Table1.YEAR Ideally I'd like to get a result that gives me a total sum of the counts by year, so instead of: | REGION 1 | | REGION 2 | | YEAR | Total | | YEAR | Total | | 2010 | 5 | | 2010 | 1 | | 2009 | 2 | | 2009 | 3 | | | | | 2008 | 4 | I'd have: | MERGED | | YEAR | Total | | 2010 | 6 | | 2009 | 5 | | 2008 | 4 | I've tried a variety of JOINs and other ideas but I think I'm caught up on the SUM and COUNT issue. Any help would be appreciated, thanks!

    Read the article

  • PHP Sum Array - sum only elemants of an array

    - by Homer_J
    Hi all, I have have an array as follows: $row[6] This section of the array has 4 numbers within it that I can display and use without any problems, what I'd like to be able to do is sum the first two numbers and the last two numbers separately. Is there any way to do this? Thanks in advance, Homer.

    Read the article

  • Quickly retrieve the subset of properties used in a huge collection in C#

    - by ccornet
    I have a huge Collection (which I can cast as an enumerable using OfType<()) of objects. Each of these objects has a Category property, which is drawn from a list somewhere else in the application. This Collection can reach sizes of hundreds of items, but it is possible that only, say, 6/30 of the possible Categories are actually used. What is the fastest method to find these 6 Categories? The size of the huge Collection discourages me from just iterating across the entire thing and returning all unique values, so is there a faster method of accomplishing this? Ideally I'd collect the categories into a List.

    Read the article

  • How to select from tableA sum of grouped numbers from tableB above their sums average in Oracle?

    - by Nazgulled
    I have data like this: tableA.ID --------- 1 2 3 tableB.ID tableB.NUM -------------------- 1 10 1 15 2 18 3 12 2 15 3 13 1 12 I need to select tableA IDs where the sum of their NUMs in tableB is above the average of all tableA IDs sums. In other words: SUM ID=1 -> 10+15+12 = 37 SUM ID=2 -> 18+12+15 = 45 SUM ID=3 -> 12+13 = 25 AVG ALL IDs -> (37+45+25)/3 = 35 The SELECT must only show ID 1 and 2 because 37 35, 45 35 but 25 < 35. This is my current query which is working fine: SELECT tableA.ID FROM tableA, tableB WHERE tableA.ID = tableB.ID HAVING SUM(tableB.NUM) > ( SELECT AVG(MY_SUM) FROM ( SELECT SUM(tableB.NUM) MY_SUM FROM tableA, tableB WHERE tableA.ID = tableB.ID GROUP BY tableA.ID ) ) GROUP BY tableA.ID But I have a feeling there might be a better way without all those nested SELECTs. Perhaps 2, but 3 feels like too much. I'm probably wrong though. For instance, why can't I do something simple like this: SELECT tableA.ID FROM tableA, tableB WHERE tableA.ID = tableB.ID HAVING SUM(tableB.NUM) > AVG(SUM(tableB.NUM)) GROUP BY tableA.ID Or this: SELECT tableA.ID, SUM(tableB.NUM) MY_SUM FROM tableA, tableB WHERE tableA.ID = tableB.ID HAVING MY_SUM > AVG(MY_SUM) GROUP BY tableA.ID

    Read the article

  • sum not working properly abap

    - by Eva Dias
    I'm trying to sum up some values but it keeps giving me weird values. I'm posting the code to help, and an image too of what is happening. at end of kunnr. soma-waers = <fs_main-waers. soma-wrbtr = <fs_main-wrbtr. soma-fwste = <fs_main-fwste. soma-hwaer = <fs_main-hwaer. soma-dmbtr = <fs_main-dmbtr. soma-hwste = <fs_main-hwste. APPEND soma TO it_soma. LOOP AT it_soma INTO soma. IF sy-tabix = 1. FORMAT COLOR COL_TOTAL INTENSIFIED OFF. SUM. WRITE: "/ sy-uline(137), / sy-vline NO-GAP, 'Subtotal' NO-GAP, '-' NO-GAP, soma-waers, 63 sy-vline NO-GAP, 64 soma-wrbtr NO-GAP, sy-vline NO-GAP, soma-fwste NO-GAP, sy-vline NO-GAP, soma-hwaer NO-GAP, sy-vline NO-GAP, soma-dmbtr NO-GAP, sy-vline NO-GAP, soma-hwste NO-GAP, sy-vline NO-GAP, / sy-uline(137). ELSE. ENDIF. ENDLOOP. ENDAT.

    Read the article

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