average

Calculate Weighted Average in sql for duplicate items

瘦欲@ 提交于 2019-12-13 05:46:48
问题 TABLE ITEM | SKU | QUANT | ITEM LANDING -----+-------+---------+----------------- ABC | A-B-C | 5 | 500 ABC | A-B-C | 10 | 400 DEF | D-E-F | 5 | 200 GHI | G-H-I | 6 | 300 JKL | J-K-L | 5 | 800 JKL | J-K-L | 10 | 600 RESULT ITEM NAME | ITEM SKU | QUANT | Weighted Average ----------+-----------+--------+--------------------- ABC | A-B-C | 15 | 433.33 DEF | D-E-F | 5 | 200 GHI | G-H-I | 6 | 300 JKL | J-K-L | 15 | 666.66 I want to calculate weighted average for duplicate items ((first landing

Omitting and finding average in R

允我心安 提交于 2019-12-13 04:48:01
问题 I am given stores ID's and the amount the store earned. What I would like to do is, omit all but one store (lets say store ID: 333333 and 222222 in this case) and then find the average amount of store 111111. YEAR STORE ID AMOUNT 2012 111111 11 2012 222222 12 2012 111111 4 2012 222222 4 2012 111111 45 2012 333333 7 All help is appreciated! 回答1: While mean(df$AMOUNT[df[, "STORE ID"] == 1111111]) will work for your specific example, you might also want to checkout the dplyr package which

Multiple columns of data and getting average R program

这一生的挚爱 提交于 2019-12-13 04:24:56
问题 I asked a question like this before but I decided to simplify my data format because I'm very new at R and didnt understand what was going on....here's the link for the question How to handle more than multiple sets of data in R programming? But I edited what my data should look like and decided to leave it like this..in this format... X1.0 X X2.0 X.1 0.9 0.9 0.2 1.2 1.3 1.4 0.8 1.4 As you can see I have four columns of data, The real data I'm dealing with is up to 2000 data points....

MySQL average number of hours between created datetimes for a specific time interval

心已入冬 提交于 2019-12-13 03:43:50
问题 I have a table with a field called "created" which is a datetime field. Assume NOW() is midnight on 2013-07-21, so NOW() = 2013-07-21 23:59:59 Now let's say I query for all records WHERE created BETWEEN DATE_SUB(NOW(), INTERVAL 4 DAYS) AND NOW() Let's say that returns results like this: 2013-07-18 08:00:00 2013-07-19 08:00:00 2013-07-20 08:00:00 2013-07-21 08:00:00 I want to add the start and end datetime for the interval I used (4 days) to that result set, so now I have: 2013-07-18 00:00:00

Mysql get average and sum of columns and group by year & month

谁说胖子不能爱 提交于 2019-12-13 00:53:53
问题 I have a query wherein I need to return the average of the price and the sum of the qty and group the results by year and month. This is the start of my query, just don't know how to get the results that I need. SELECT asin, price, qtyTotal, qtyReserved, qtyWarehouse, qtyFulfillable, qtyUnsellable, perUnitVolume, YEAR(reportDate), MONTH(reportDate), DAY(reportDate) FROM Table WHERE name = 'XXXXXXX' ORDER BY reportDate ASC id | name | price | qty | unitVol | year | month | day | reportDate ---

Sum and Average of a series of numbers inputed to a text field

左心房为你撑大大i 提交于 2019-12-12 19:20:53
问题 I am trying to create an application that calculates the sum and average of numbers that are inputted into a text field separated by spaces. I am stuck on the part where you have to put in a loop to calculate the sum and avg from the spaced inputs. I have been using console.log to test throughout while I type my code. Any guidance would be helpful. First time doing javascript. I have looked at the forms on this website and it seems like all the sum/avg javascript questions arent input text

Compute average sales per day in MySQL

不羁岁月 提交于 2019-12-12 14:57:38
问题 In my database I have a table with two columns. The first column contains dates and the second is a count variable. I was wondering if it is possible to compute the average counts for each weekday based on the dates and counts. In the following a small example: Table: Date Count 02/01/2005 100 02/02/2005 200 02/03/2005 300 ... ... Output: Days Average Monday 120.5 Tuesday 200.2 Wednesday 300.5 回答1: You could a series of avg calls on case expression extracting the day's name: SELECT AVG(CASE

Power BI Rolling Average DAX to plot correctly on Column Chart

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-12 14:49:43
问题 I have a problem with the measure of the 3mth rolling average to visualise it correctly on the graph. The data model is here: https://docs.google.com/spreadsheets/d/1naChcuZtjSbk0pVEi1xKuTZhSY7Rpabc0OCbmxowQME/edit?usp=sharing I am using the formula below to calculate 3mth average through a measure: Product3Mth = CALCULATE(SUM('Table'[Product A uncum]);DATESINPERIOD('Table'[Date];LASTDATE('Table'[Date]);-3;MONTH))/3 When I am plotting it as a table it is showing right values for each month.

Pyspark:How to calculate avg and count in a single groupBy? [duplicate]

心已入冬 提交于 2019-12-12 12:14:25
问题 This question already has answers here : Multiple Aggregate operations on the same column of a spark dataframe (3 answers) Closed last year . I would like to calculate avg and count in a single group by statement in Pyspark. How can I do that? df = spark.createDataFrame([(1, 'John', 1.79, 28,'M', 'Doctor'), (2, 'Steve', 1.78, 45,'M', None), (3, 'Emma', 1.75, None, None, None), (4, 'Ashley',1.6, 33,'F', 'Analyst'), (5, 'Olivia', 1.8, 54,'F', 'Teacher'), (6, 'Hannah', 1.82, None, 'F', None), (7

Creating calculated fields in sql

我的未来我决定 提交于 2019-12-12 09:54:40
问题 This will seem rudimentary but I can't find a concise example online that matches up. I have three fields; m1 , m2 , and m3 . I need to create a column or field that is the average of them three. The calculated field would be titled employment. Would the following code be suffice? ALTER TABLE dbo.tablename ADD Employment AS Select ((m1+m2+m3)/3) Sample data m1 20 20 30 m2 15 17 25 m3 60 77 13 desired result. Name m1 m2 m3 Employment Auto body 20 20 30 23 Auto Parts 15 17 25 19 Auto Sales 60