Group by aggregate functions in LINQ

I have a SQL query of the following type and I was trying to fetch the data in my C# application using LINQ select sum(CASE when outcome = 0 then samplingweight else 0 end) tpcount, sum(CASE when outcome = 1 then samplingweight else 0 end) fpcount, s

Aggregating different rows in a single SQL query

Sorry, I didn't come up with a good title for the question, so feel free to change it accordingly. I may describe my question with a minimal example in MS SQL server 2012: create table #tmp ( RowID varchar(10), SectionCode int, SectionName varchar(10

SQL pivot with unbalanced data

I'm deeling with the Pivot function if it is possible to "fill up" data not included in the main table. My table includes these data: create table tmpData (objID INT, colID varchar(5), value varchar(50)); insert into tmpData (objId, colId, value

aggregate a column containing numbers and strings

I have a dataframe in my R script that looks something like this: ID B C 1539 Blue 8 1539 Blue 4 1539 Red 9 1539 Red 13 1539 Yellow NCAA 3574 Green RA 3574 Green RA 3574 Green RA 3574 Red 1 3574 Red 1 How do I aggregate column C and transform the dat

The SSRS report displays data for different dates

My report(which calculates attendance %) shows aggregated data if I remove the sessiondate field. But I need it as users need to run it each month(currently we run query manually) So, I have sessiondate field in my query which is based on start and e

Continuous aggregates on large datasets

I'm trying to think of an algorithm to solve this problem I have. It's not a HW problem, but for a side project I'm working on. There's a table A that has about (order of) 10^5 rows and adds new in the order of 10^2 every day. Table B has on the orde

Collection of parallel aggregates

I have seen code for parallel aggregation for basic types, e.g. Parallel.For<int>(0, result.Count, () => 0, (i, loop, subtotal) => { subtotal += result[i]; return subtotal; }, (x) => Interlocked.Add(ref sum, x) ); I was wondering if there w

Group data by model in R

I have R data frame with hundreds of rows as word Freq seed 4 seeds 3 contract 2 contracting 2 river 1 I would like to group the data by patterns, say seed + seeds ... that looks like word Freq seed 7 contract 4 river 1 Here is potentially another wa

Aggregation correlation strategy based on the XML payload

Issue: How to correlate messages for an aggregator based on a XML value in the payload? I have a scenerio where I call a third party application and it only gives back an xml response. Based on an xml value in the payload I would like to correlate th

SQL - multiple aggregation from multiple tables

Apologise if this has already been asked. Lossely i've these table create table sales ( sale_date timestamp not null, amount double precision } create table customers ( event_date timestamp not null, cust_cnt integer } create table details ( detail_d

R aggregate by large number of columns

I have a data frame (df) that has about 40 columns, and I want to aggregate using a sum on 4 of the columns. Outside of the 4 I want to sum, each unique value in column 1 corresponds to identical values across the rest of the columns, and I want to k

Drag an aggregation request for one-hour periods

In Postgres 9.2, I have a table containing measures taken at specific points in time: CREATE TABLE measures (dt timestamptz, measure integer); INSERT INTO measures VALUES ('2015-01-13 12:05', 10), ('2015-01-13 12:30', 8), ('2015-01-13 13:02', 16), ('

How to generate duplicate rows

I have the following data: x1 x2 x3 x4 34 14 45 53 2 8 18 17 34 14 45 20 19 78 21 48 2 8 18 5 In rows 1 and 3; and 2 and 5 the values for columns X1;X2,X3 are equal. How can I output only those 4 rows, with equal numbers? The output should be in the

Select count and aggregate, but only single

I have a database (MSSQL) with a table as follows: CREATE TABLE [dbo].[Ciphers]( [Time] [datetime] NULL, [Hostname] [varchar](50) NULL, [ClientIP] [varchar](50) NULL, [UserAgent] [varchar](550) NULL, [CipherName] [varchar](200) NULL, [CipherVersion]

Aggregate, date, values

I am new to R and am trying to aggregate the results and find min of dates. For example if I have ID Date Value 0 2013-06-02 1 0 2013-04-02 3 0 2013-02-02 5 1 2013-08-02 6 1 2013-04-02 7 1 2013-12-02 9 The result I am looking for is like: ID Date Val

Appropriate phpdoc comment for the itteratable object?

i'm having a bit of a problem trying to get a correct autocompletion for the following code example. I'm using PHPStorm 7 on a Win7 machine. First just a simple class. /** * Class myObject */ class myObject { /** * some method */ public function myMe

How to get aggregated data per week using the Entity Framework

I have a backend table named "VideoData" which has data in the following form: VideoID RecordingStarted RecordingEnded ============================================================== abc123 2013-03-01 15:30:00 2013-03-01 15:40:00 def123 2013-03-0

Group by and & ldquo; first & rdquo; or & ldquo; min & rdquo;

I have a table "messages" with the columns id,from,to,datetime,subject,body. I want to get subject and body of the latest message for each sender (from). Here is my query SELECT min(subject) as tsubject,min(body) as tbody FROM messages WHERE &qu

How to aggregate efficiently on scattered data

I have a large dataset with 1008412 observations, the columns are customer_id (int), visit_date (Date, format: "2010-04-04"), visit_spend (float). This date function for the aggregate maps week numbers of interest to the range 13-65: weekofperio

summarize the values ​​on a tree

I used a Tree control to view some hierarchical items base on a nested (parent child) table . Every node has a NameValue format that accept either a name and value . But only Leaves (last nodes) have integer values and values of parents are left blan

Ruby equivalent of the C # Linq Aggregate method

Whats the ruby equivalent of Linq Aggregate method. It works something like this var factorial = new[] { 1, 2, 3, 4, 5 }.Aggregate((acc, i) => acc * i); the variable acc is getting accumulated every time the value from the array sequence is passed to

SQL Recurrence

Hi my table looks some what like this. OldPart | NewPart | Demand ========================== C | D | 3 F | | 1 A | B | 5 D | E | 2 E | F | 0 B | C | 3 Z | | 1 M | | 7 Y | Z | 10 What I am trying to do is come up with a final table where the newest pa