group-by

Ntile and decile function depended on two columns in R [duplicate]

社会主义新天地 提交于 2019-12-25 02:58:50
问题 This question already has answers here : Aggregate / summarize multiple variables per group (e.g. sum, mean) (6 answers) Closed 11 months ago . I would like to have a new column with Ntile but it should depend on column 1 - "year" and show the ntile number for column 2 - "mileage". year mileage <dbl> <dbl> 1 2011 7413 2 2011 10926 3 2011 7351 4 2011 11613 5 2012 8367 6 2010 25125 mydata$Ntile <- ntile(mydata$mileage, 10) I know the easy to use function ntile , but I do not know how to make it

Get MAX row for GROUP in MySQL

百般思念 提交于 2019-12-25 02:53:21
问题 I have the following data: +---------+----------+----------+--------+ | id | someId | number | data | +---------+----------+----------+--------+ | 27 | 123 | 1 | abcde1 | | 28 | 123 | 3 | abcde2 | | 29 | 123 | 1 | abcde3 | | 30 | 123 | 5 | abcde4 | | 31 | 124 | 4 | abcde1 | | 32 | 124 | 8 | abcde2 | | 33 | 124 | 1 | abcde3 | | 34 | 124 | 2 | abcde4 | | 35 | 123 | 16 | abcde1 | | 245 | 123 | 3 | abcde2 | | 250 | 125 | 0 | abcde3 | | 251 | 125 | 1 | abcde4 | | 252 | 125 | 7 | abcde1 | | 264 |

Show different group header and footer per section

孤人 提交于 2019-12-25 02:22:37
问题 Can anyone tell me how to show SSRS group header and footer in SSRS 2008R2? The idea is to have an approach like in Crystal Reports, where we can add a group header/footer and do our own design in that section on every page based on page break functionality. Does anyone know an approach for this in SSRS? I should be able to show my own design/controls/dataset fields group header area, and be able to see it on every page based on the page break by group. Would also appreciate if you can share

Order column by certain criteria in mysql

ぃ、小莉子 提交于 2019-12-25 02:19:25
问题 I need to be able to order my output data in a proper way using MySQL . I'm using ORDER BY so far and everything was working correctly until now. Let's say I have something like this: Table VEHICLES : ID | Name | MainGroup | SubGroup 1 | A | Vehicle | Truck 2 | B | Vehicle | Car 3 | C | Vehicle | Car 4 | D | Vehicle | Truck 5 | E | Vehicle | Truck 6 | F | Vehicle | Motorbike I was using this: SELECT * FROM Vehicles WHERE MainGroup=Vehicle ORDER BY Subgroup; When I get selections they are not

MySQL Group By get title column with smallest date value

╄→гoц情女王★ 提交于 2019-12-25 02:13:38
问题 I have a query like: SELECT * FROM table GROUP BY sid ORDER BY datestart desc LIMIT 10 which returns the last 10 sid groups. For each of these groups, I need the title column of the row with the lowest datestart value I tried using SELECT *, min(datestart) but that didn't return the row with the smallest datestart value, just the lowest datestart. I need the title from the lowest datestart. (Relevant) Table Structure: CREATE TABLE `table` ( `title` varchar(1000) NOT NULL, `datestart`

Mysql group rows

不羁的心 提交于 2019-12-25 01:53:23
问题 I have a table with: Id (id of rider) Time (is the time that he has done) Session (number session where the time was done) idlap idRider session time 1 45652 1 4 2 54645 1 2 3 45652 2 2 4 54582 2 1 5 51284 1 3 6 54582 1 3 7 54645 2 4 8 51284 2 5 9 54582 2 2 I wonder how to query in mysql a result like: idRider |fast sesion | count laps 45652 | 2 | 1 54645 | 1 | 1 51284 | 3 | 1 54582 | 2 | 2 The query should return in wich session the rider got the best time(fast session) and count the number

Join two tables and apply group by, but change sort order

余生长醉 提交于 2019-12-25 01:33:28
问题 I have two tables, event and version. An event has many versions. I want to perform an inner join and get THE LAST version for each event. QUERY SELECT * FROM events.event e INNER JOIN events.version v ON (e.version_id = v.id) GROUP BY e.event_id TABLE EVENT id event_id version_id updated 1 1 7 03/08/2018 2 2 8 06/06/2018 3 2 9 02/07/2018 TABLE VERSION id name description comments 7 Dinner A fancy dinner Z Comment Z 8 Breakfast Fancy breakfast Y Comment Y 9 Breakfast Fancy breakfast X Comment

Percentage Per Group From Count

人走茶凉 提交于 2019-12-25 01:26:16
问题 I have the following scenario of the number of people and the type entering the premises, rounded to an hour. Date-time Type 2014-01-01 01:00:00 Employee 2014-01-01 01:00:00 Visitor 2014-01-01 01:00:00 Employee 2014-01-01 02:00:00 Visitor 2014-01-01 02:00:00 Visitor 2014-01-01 02:00:00 Visitor 2014-01-01 02:00:00 Employee 2014-01-01 03:00:00 Employee 2014-01-01 03:00:00 Visitor 2014-01-01 03:00:00 Employee I am doing a query to group them together select count(*), HOUR(Date-Time), Type from

Partition by in Impala SQL throwing an error

北慕城南 提交于 2019-12-25 01:03:13
问题 I am trying to calculate the running total of loss by the months on Impala using TOAD The following query is throwing the error - select list expression not produced by aggregation output (missing from group by clause ) select segment, year(open_dt) as open_year, months, sum(balance) sum(loss) over (PARTITION by segment,year(open_dt) order by months) as NCL from tableperf where year(open_dt) between 2015 and 2018 group by 1,2,3 回答1: You are mixing aggregation and window functions. I think you

Mysql Sum and Group By Method

丶灬走出姿态 提交于 2019-12-25 00:55:49
问题 Input Date Points Email 2012-07-01 5 a@sample.com 2012-07-01 6 b@sample.com 2012-07-01 2 c@sample.com 2012-07-02 5 d@sample.com 2012-07-03 8 e@sample.com 2012-07-03 7 f@sample.com 2012-07-03 1 y@sample.com 2012-07-04 3 x@sample.com 2012-07-04 2 f@sample.com 2012-07-05 3 g@sample.com 2012-07-05 9 b@sample.com Output Date Points 2012-07-01 13 2012-07-02 5 2012-07-03 16 2012-07-04 5 2012-07-05 12 Suggest me an MySQL Query for output like the above 回答1: try SELECT `date`, SUM(`Points`) AS