group-by

SQL group by date, but get dates w/o records too

筅森魡賤 提交于 2019-12-19 04:22:37
问题 Is there an easy way to do a GROUP BY DATE(timestamp) that includes all days in a period of time, regardless of whether there are any records associated with that date? Basically, I need to generate a report like this: 24 Dec - 0 orders 23 Dec - 10 orders 22 Dec - 8 orders 21 Dec - 2 orders 20 Dec - 0 orders 回答1: Instead of using GROUP BY, make a table (perhaps a temporary table) which contains the specific dates you want, for example: 24 Dec 23 Dec 22 Dec 21 Dec 20 Dec Then, join that table

Order Players on the SUM of their association model

巧了我就是萌 提交于 2019-12-19 03:25:12
问题 I have a database with 6500 players and each player has an average of 15 game results . Use case I want to generate a list of players, ordered by the sum of their prize money (a field in the results table). I prefer this to be in some sort of scope, so I can also filter the list on the player's country, etc. Performance I have seen posts that mention a cache_counter field for performance. In my case I have thousands of result records (75.000+) so I don't want the calculations being done every

Difference between WHERE and HAVING in SQL [duplicate]

时光怂恿深爱的人放手 提交于 2019-12-19 03:24:32
问题 This question already has answers here : Closed 8 years ago . Possible Duplicate: SQL: What's the difference between HAVING and WHERE? I have seen various discussions on WHERE and HAVING . I still have a question: is HAVING used only when considering aggregates, or can it be used in more general terms: whenever you have created or aliased a field in your query? I know that WHERE should always be used when possible. 回答1: HAVING specifies a search for something used in the SELECT statement. In

Column invalid in the select list because it is not contained in either an aggregate function or the GROUP BY clause

别等时光非礼了梦想. 提交于 2019-12-19 02:47:30
问题 We have a table which will capture the swipe record of each employee . I am trying to write a query to fetch the list of distinct employee record by the first swipe for today. We are saving the swipe date info in datetime column. Here is my query its throwing exception. select distinct [employee number], [Employee First Name] ,[Employee Last Name] ,min([DateTime]) ,[Card Number] ,[Reader Name] ,[Status] ,[Location] from [Interface].[dbo].[VwEmpSwipeDetail] group by [employee number] where

Pandas - group by consecutive ranges

◇◆丶佛笑我妖孽 提交于 2019-12-19 02:31:15
问题 I have a dataframe with the following structure - Start, End and Height. Some properties of the dataframe: A row in the dataframe always starts from where the previous row ended i.e. if the end for row n is 100 then the start of line n+1 is 101. The height of row n+1 is always different then the height in row n+1 (this is the reason the data is in different rows). I'd like to group the dataframe in a way that heights will be grouped in buckets of 5 longs i.e. the buckets are 0, 1-5, 6-10, 11

Group by range using linq [duplicate]

老子叫甜甜 提交于 2019-12-19 02:14:51
问题 This question already has answers here : Group by variable integer range using Linq (4 answers) Closed 3 years ago . how can we use groupped ranges for equal or greater than ? var data = new[] { new { Id = 0, Price = 2 }, new { Id = 1, Price = 10 }, new { Id = 2, Price = 30 }, new { Id = 3, Price = 50 }, new { Id = 4, Price = 120 }, new { Id = 5, Price = 200 }, new { Id = 6, Price = 1024 }, }; var ranges = new[] { 10, 50, 100, 500 }; var grouped = data.GroupBy( x => ranges.FirstOrDefault( r =

Grouping MySQL datetime into intervals irrespective of timezone

本小妞迷上赌 提交于 2019-12-18 22:33:12
问题 This question has been asked before but I am facing a slightly different problem. I have a table which logs events and stores their timestamps (as datetime). I need to be able to break up time into chunks and get number of events that occurred in that interval. The interval can be custom (Say from 5 minutes to 1 hour and even beyond). The obvious solution is to convert the datetime to unix_timestamp divide it by number of seconds in the interval, take its floor function and multiply it back

Efficiently querying a huge time series table for one row every 15 minutes

ⅰ亾dé卋堺 提交于 2019-12-18 18:00:50
问题 I have two tables, conttagtable (t) and contfloattable (cf). T has about 43k rows. CF has over 9 billion. I created an index on both tables on the tagindex column on both tables. This column can be thought of as a unique identifier for conttagtable and as a foreign key into conttagtable for confloattable . I didn't explicitly create a PK or foreign key on either table relating to the other, although this data is logically related by the tagindex column on both tables as if conttagtable

dplyr group by not working in Shiny

一曲冷凌霜 提交于 2019-12-18 17:02:09
问题 I am working with R shiny application,in that i have two dropdown boxes. first drop down is populated with categorical variables and second is populated with numerical variables. And then I am applying groupby on categorical variable. Here is my code. dataset<- dataUpload() var1 <- as.character(input$variable1) var2 <- as.character(input$variable2) v$data <- dataset %>% group_by(dataset[,var1]) %>% summarize(Sum=sum(dataset[,var2])) %>% arrange(desc(Sum)) And it gives me following output.

Is there an “ungroup by” operation opposite to .groupby in pandas?

雨燕双飞 提交于 2019-12-18 14:48:08
问题 Suppose we take a pandas dataframe... name age family 0 john 1 1 1 jason 36 1 2 jane 32 1 3 jack 26 2 4 james 30 2 Then do a groupby() ... group_df = df.groupby('family') group_df = group_df.aggregate({'name': name_join, 'age': pd.np.mean}) Then do some aggregate/summarize operation (in my example, my function name_join aggregates the names): def name_join(list_names, concat='-'): return concat.join(list_names) The grouped summarized output is thus: age name family 1 23 john-jason-jane 2 28