average

How to aggregate the average of a calculation based on two columns?

梦想的初衷 提交于 2019-12-11 13:48:58
问题 I want to write a Django query to give me the average across all rows in my table. My model looks like class StatByDow(models.Model): total_score = models.DecimalField(default=0, max_digits=12, decimal_places=2) num_articles = models.IntegerField(default=0) day_of_week = IntegerField( null=True, validators=[ MaxValueValidator(6), MinValueValidator(0) ] ) and I attempt to calculate the average like this everything_avg = StatByDow.objects.all().aggregate(Avg(Func(F('total_score') / F('num

SQL Group by using the First N elements in each group [duplicate]

心已入冬 提交于 2019-12-11 11:23:50
问题 This question already has an answer here : Top N per Group Sql problem in mysql (1 answer) Closed 6 years ago . Suppose I have the next table: +------------+---------+ | MovieId | rating | +------------+---------+ | 1 | 4 | | 1 | 3 | | 1 | 2 | | 1 | 4 | | 1 | 5 | | 2 | 3 | | 2 | 4 | | 2 | 2 | | 3 | 1 | | 3 | 2 | | 3 | 3 | | 3 | 5 | | 4 | 4 | | 4 | 2 | +------------+---------+ I would like to get the average by group BUT using the first 2 elements on each group. Example: +------------+--------

Need Help on Average Python [closed]

杀马特。学长 韩版系。学妹 提交于 2019-12-11 10:49:18
问题 This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, visit the help center. Closed 6 years ago . Find the average of the values in the field [quant] greater than or equal to (337) this is the quant field quant 100 7 109 204 28 292 105 254 441 401 410

CakePHP 2.1 Avg function for query

拜拜、爱过 提交于 2019-12-11 10:28:11
问题 I am using cakephp 2.1 and I wanna get average of movie ratings for perticular movie. Where 'Movie' is a model and it contains 'Language' and 'CriticReview' as models. The array structure is as follows. array( (int) 0 => array( 'Movie' => array( 'id' => '4', 'name' => 'Maattrraan', 'cover_image' => '/movies/4d0d1c41d956a2cb2ab93603d1fdf70c.jpg', 'release' => '2012-10-12', 'runtime' => '', 'budget' => '65 crore', 'box_office' => '', 'language_id' => '2', 'industry_id' => '3' ), 'Language' =>

Find the average salary several months back - MySQL

别说谁变了你拦得住时间么 提交于 2019-12-11 09:27:25
问题 I want to find the average salary of the staffs who started work within 8 months ago. I tried making the code but somehow it's displaying NULL.. SELECT AVG(salary) FROM Staff WHERE salary = DATE_SUB(sWDate, INTERVAL 8 MONTH); Everything is within this table. Can anyone help me out please? I'm not sure what I've done wrong. Thanks. 回答1: Why salary = DATE_SUB(sWDate, INTERVAL 8 MONTH) ? WITHIN 8 MONTHS: SELECT AVG(salary) FROM Staff WHERE sWDate <= NOW() AND sWDate >= DATE_SUB(Now(), INTERVAL 8

MySQL - working out the AVG for a subset of MAX values

僤鯓⒐⒋嵵緔 提交于 2019-12-11 07:35:44
问题 I have a table with columns 'Date, Name, Score'. I wish to get the MAX(Score) for rows which share a common value (for e.g. the same date or even name), before averaging them to give me a figure, for example: ---- Date -----| -- Name -- | Score 2010-10-10 | John Smith | 86 2010-06-05 | Tedi Jones | 71 2010-10-10 | John Smith | 52 2010-06-05 | Tedi Jones | 68 2010-08-08 | Joe Bloggs | 79 2010-10-10 | John Smith | 46 So doing a MAX(Score) on the above would give me 86. However, what I'd like is

R Programming Calculate Rows Average

痞子三分冷 提交于 2019-12-11 06:04:35
问题 How to use R to calculate row mean ? Sample data: f<- data.frame( name=c("apple","orange","banana"), day1sales=c(2,5,4), day1sales=c(2,8,6), day1sales=c(2,15,24), day1sales=c(22,51,13), day1sales=c(5,8,7) ) Expected Results : Subsequently the table will add more column for example the expected results is only until AverageSales day1sales.4 . After running more data, it will add on to day1sales.6 and so on. So how can I count the average for all the rows? 回答1: with rowMeans > rowMeans(f[-1]) #

Group index by minute and compute average

流过昼夜 提交于 2019-12-11 05:56:41
问题 So I have a pandas dataframe called 'df' and I want to remove the seconds and just have the index in YYYY-MM-DD HH:MM format. But also the minutes are then grouped and the average for that minute is displayed. So I want to turn this dataFrame value 2015-05-03 00:00:00 61.0 2015-05-03 00:00:10 60.0 2015-05-03 00:00:25 60.0 2015-05-03 00:00:30 61.0 2015-05-03 00:00:45 61.0 2015-05-03 00:01:00 61.0 2015-05-03 00:01:10 60.0 2015-05-03 00:01:25 60.0 2015-05-03 00:01:30 61.0 2015-05-03 00:01:45 61

MS Access: How can I average a list of quantities on a report where the quantities are not zero?

a 夏天 提交于 2019-12-11 05:39:13
问题 I have a report. This reports returns a lot of rows. One of the columns is qty_req (quantity required). I need to AVG() this column and put the value of the average at the bottom of the report. The problem is that sometimes some rows have a zero in this column. I want the average to exclude any rows where there is a zero. How can I accomplish this? What I've tried: I tried using DAvg in the query but it made the query time enormous. 回答1: Avg() ignores Null values. So you can use an IIf()

MySQL AVG(TIMESTAMPDIFF) with GROUP BY

邮差的信 提交于 2019-12-11 05:27:44
问题 I have two tables user (one) and transaction (many) and I need to get the average time in days from when a user was created to when they made their first transaction. I'm using AVG(TIMESTAMPDIFF) which is working well, except that the GROUP BY returns an average against every user instead of one single average for all unique users in the transaction table. If I remove the GROUP BY , I get a single average figure but it takes into account multiple transactions from users, whereas I just want