group-by

Using case to convert column values to row values in mysql

对着背影说爱祢 提交于 2020-01-07 02:21:08
问题 I am trying to use case statements in a mysql query to convert rows to columns. I have seen other questions like this here, but I can't get it to work for some reason. Here is example raw data. last_name question_number result Jones 1 correct Jones 2 correct Jones 3 incorrect Jones 4 correct Smith 1 incorrect Smith 2 correct Smith 3 correct Smith 4 incorrect Here is what I want to end up with last_name Q1 Q2 Q3 Q4 Jones correct correct incorrect correct Smith incorrect correct correct

How to build batches/buckets with linq

有些话、适合烂在心里 提交于 2020-01-06 21:12:16
问题 I need to create batches from a lazy enumerable with following requirements: Memory friendly: items must be lazy loaded even within each batch ( IEnumerable<IEnumerable<T>> , excludes solution building arrays) the solution must not enumerate twice the input (excludes solutions with Skip() and Take() ) the solution must not iterate through the entire input if not required (exclude solutions with GroupBy ) The question is similar but more restrictive to followings: How to loop through

Find average value for array of hashes using multiple group by

大城市里の小女人 提交于 2020-01-06 20:18:06
问题 based on Summarize array of objects and calculate average value for each unique object name I could partially solve my problem. I did group by ed_id but I need to group by ed_id and then el_id and to get average value based on those group by, so here is my array of hashes: a = [ { ed_id: 1, el_id: 127, value: 2 }, { ed_id: 1, el_id: 127, value: 6 }, { ed_id: 1, el_id: 129, value: 3 }, { ed_id: 1, el_id: 129, value: 13 }, { ed_id: 2, el_id: 127, value: 5 }, { ed_id: 2, el_id: 127, value: 9 },

Aggregate hourly means based on compound field expression

扶醉桌前 提交于 2020-01-06 16:30:15
问题 I am trying to calculate the hourly mean of x in a data frame similar to this: min hour day month year x 1 10 22 31 12 2013 18.3 2 30 22 31 12 2013 16.5 3 50 22 31 12 2013 15.7 4 10 23 31 12 2013 16.7 5 30 23 31 12 2013 18.0 6 50 23 31 12 2013 18.1 7 10 0 1 1 2014 17.4 8 30 0 1 1 2014 15.4 9 50 0 1 1 2014 16.9 I have tried different things with the aggregate function but without luck. So what I want is to calculate the mean of x if the value of hour , day , month , year are the same. The

For each row of one table, count entries in another table pointing to each of those rows in Oracle

不想你离开。 提交于 2020-01-06 15:52:16
问题 Not sure the title explains the problem well; this is what I'm working with, I have the following tables, -- table = kms_doc_ref_currnt_v DOC_ID VARCHAR2(19) TO_DOC_ID VARCHAR2(19) BRANCH_ID NUMBER(8) REF_TYP_CD VARCHAR2(20) -- table = kms_fil_nm_t DOC_ID VARCHAR2(19) PRIMARY KEY UNIQUE For example, I can get a count of all kms_doc_ref_currnt_v records that have a to_doc_id = 59678 , where 59678 is one value in kms_fil_nm_t , with this query, select 'doc_id 59678 has ' || count(to_doc_id) as

Mysql Group By implementation details - which row mysql chooses in a Group By query without operators?

穿精又带淫゛_ 提交于 2020-01-06 15:22:16
问题 I have a table with multiple rows per "website_id" CREATE TABLE `MyTable` ( `id` bigint(20) NOT NULL AUTO_INCREMENT, `tagCheckResult` int(11) DEFAULT NULL, `website_id` bigint(20) DEFAULT NULL, PRIMARY KEY (`id`), KEY `IX_website_id` (`website_id`), ) ENGINE=InnoDB; I am trying to select the latest entry per website_id -- This creates a temporary table with the last entry per website_id, and joins it -- to get the entire row SELECT * FROM `WebsiteStatus` ws1 JOIN ( SELECT MAX(id) max_id,

“column XYZ must be in group by” --> “cannot group by aggregate column”

谁说胖子不能爱 提交于 2020-01-06 15:17:36
问题 i have trouble with following sql-statement (trimmed): SELECT nr, (CASE WHEN SUM(vkdtab.amount*liter)<>0 AND jjjjmm BETWEEN 201001 and 201009 THEN SUM(net)/SUM(vkdtab.amount*liter) ELSE 0 END) as return FROM tab GROUP BY 1,2,3 It should give me the amount/liter of items in a special timeframe, but I get the error: column return must be in group by After I add that column: cannot group by aggregate column . This is functional, just without the timeframe: CASE WHEN SUM(vkdtab.amount*liter)<>0

How to group by multiple columns in SQL Server

核能气质少年 提交于 2020-01-06 15:11:21
问题 I understand how GROUP BY works and I also understand why my query does not bring the results I am expecting. However, what would be the best way to eliminate duplicates in this case? Let's say we have the following tables: City Id Name --------------------- 1 Seattle 2 Los Angeles 3 San Francisco Person Id Name CityId ---------------------------- 1 John Smith 1 2 Peter Taylor 1 3 Kate Elliot 1 4 Bruno Davis 2 5 Jack Brown 2 6 Bob Stewart 2 7 Tom Walker 3 8 Andrew Garcia 3 9 Kate Bauer 3 I

How to do a group by in the Wordpress?

倖福魔咒の 提交于 2020-01-06 14:12:55
问题 I have a drivers post type which has a relationship called team. I want to group drivers by team so I can output them together in their groupings 'teams'. Hopefully that makes sense. I don't really understand the documentation I have a tried a few things but it seems to be missing details. This is what I have at the moment: <?php $type = 'drivers'; $args=array( 'post_type' => $type, 'post_status' => 'publish', 'paged' => $paged, 'posts_per_page' => 12, 'ignore_sticky_posts'=> 0, ); $loop =

GROUP BY only rows with a certain condition and date

纵然是瞬间 提交于 2020-01-06 14:07:11
问题 I have a basic table in my database that has a simple transactions history such as depositing money to an account, withdrawing money, and having money refunded. Each entry has a date associated with it. I have a php page that displays this transactional information row by row and it looks great. However, is there a way within the mySQL query that I can "collapse" all "refunded" money transactions into groupings by day? It's quite easy to do a GROUP_BY on the transaction type but I only want