group-by

MySQL GROUP BY behavior (when using a derived table with order by)

心已入冬 提交于 2019-12-13 02:47:38
问题 Since mysql does not enforce the Single-Value Rule (See: https://stackoverflow.com/a/1646121/1688441) does a derived table with an order by guarantee which row values will be displayed? This is for columns not in an aggregate function and not in the group by . I was looking at the question (MySQL GROUP BY behavior) after having commented on and answered the question (https://stackoverflow.com/a/24653572/1688441) . I don't agree with the accepted answer, but realized that a possible improved

mysql sum with group by for different column values

喜欢而已 提交于 2019-12-13 02:36:49
问题 create table t ( `place_id` int(11) NOT NULL , `area_sq` int (11) NOT NULL, `nxx` int(11) NOT NULL ); insert into t values(1, 50, 1); insert into t values(2, 90, 2); insert into t values(2, 20, 1); insert into t values(2, 10, 0); insert into t values(2, 10, 1); insert into t values(3, 10, 3); | PLACE_ID | AREA_SQ | NXX | |----------|---------|-----| | 1 | 50 | 1 | | 2 | 90 | 2 | | 2 | 20 | 1 | | 2 | 10 | 0 | | 2 | 10 | 1 | | 3 | 10 | 3 | above is my table called t . I need to get the

Efficient way to flag a record with min field value and common fieldX value in mysql

烂漫一生 提交于 2019-12-13 02:29:50
问题 I am trying to flag all records in a table that have the minimum value for all records with a common FieldX Value. My query was as such: TableA Update TableA as T1 Inner Join (Select ID,Name,Min(ValueField) from TableA where GroupFlag='X' Group by CommonTermField) as T2 On T1.ID=T2.ID Set MainFlag='Y'; This worked awhile back but I keep getting a timeout/table locked error and I am assuming that it is because the table is 26 million records long (with appropriate indexes). Is there a more

GroupBy DAY using Doctrine2

天涯浪子 提交于 2019-12-13 02:23:49
问题 I am looking for way to group my policies by day. I was trying a lot of examples how to do this but still there are some errors. Can anyone help me with this? Here I will show only two examples, others i was trying were similar to those. Differences were only in used SQL's functions ex(CAST, SUBSTRING, DATE...) First way i was trying is: $query = $this->getEntityManager() ->createQueryBuilder(); $query->select('count(p), p.transactionDate') ->from('GLPolicyBundle:Policy', 'p') ->andwhere('p

Foreign Key Object Missing in LINQ GroupBy?

半腔热情 提交于 2019-12-13 02:16:14
问题 I am using GroupBy in my LINQ queries. My query is working fine, except my foreign key objects are missing. Then, I tried to add Include in my query. Following is my code: public ActionResult GetEmployees() { var Emloyees = db.Employees.AsQueryable(); Emloyees.GroupBy(e=> new {e.JobTitleId, e.GenderId}) .Select(tr => new MyObject SalaryTotal = tr.Sum(r=>r.Salary) }).Include(tr=>tr.JobTitle).Include(tr=>tr.Gender).ToList(); } I am getting this exception: The result type of the query is neither

Count entries per time interval in MATLAB

别说谁变了你拦得住时间么 提交于 2019-12-13 02:15:16
问题 I'd like to count entries per time interval. Source dataset nx2 2001-03-23 05:01:33.347,55 2001-03-23 05:01:33.603,62 2001-03-23 05:01:33.977,32 2001-03-23 05:01:34.126,30 ... Example output for group count by second: 2001-03-23 05:01:33.000,3 2001-03-23 05:01:34.000,1 ... 回答1: Here is one way: % dataset data = { '2001-03-23 05:01:33.347', 55 ; '2001-03-23 05:01:33.603', 62 ; '2001-03-23 05:01:33.977', 32 ; '2001-03-23 05:01:34.126', 30 ; }; % convert to serial date (ignoring the seconds

BigQuery select data within a time interval

时光怂恿深爱的人放手 提交于 2019-12-13 02:15:03
问题 my data looks like name| From | To_City | Date of request Andy| Paris | London| 08/21/2014 12:00 Lena | Koln | Berlin | 08/22/2014 18:00 Andy| Paris | London | 08/22/2014 06:00 Lisa | Rome | Neapel | 08/25/2014 18:00 Lena | Rome | London | 08/21/2014 20:00 Lisa | Rome | Neapel | 08/24/2014 18:00 Andy| Paris | London| 08/25/2014 12:00 I want to find how many identical drive requests a person had within +/- one day. I'd love to receive a table saying: name| From | To_City | avg Date of request

SQL request with “Group by” and “max” and “join”?

守給你的承諾、 提交于 2019-12-13 02:14:42
问题 Here is a sample of my DATA: CLIENT_ATTRIBUT : ID_CLIENT | DATE_CLIENT | ATTRIBUT ----------+-------------+--------- 000000001 | 2010:03:01 | 0000010 ----------+-------------+--------- 000000001 | 2010:02:16 | 0000010 ----------+-------------+--------- 000000001 | 2010:03:04 | 0000011 ----------+-------------+--------- 000000002 | 2010:03:01 | 0001000 ----------+-------------+--------- CLIENT : ID_CLIENT | NOM_MARITAL | ----------+-------------+ 000000001 | PANTROMANI | ----------+-----------

Linq grouping .include(“Table”) returning null on Table

↘锁芯ラ 提交于 2019-12-13 02:12:35
问题 I have a linq query that is grouping by answers by QuestionGroup. I need to have the table AssessmentQuestionsReference load so that i can bind to it in my WPF app. var groupedAnswers = from a in App.ents.AssessmentAnswers.Include("AssessmentQuestions") where a.Organisations.OrganisationID == App.selectedOrganisation.OrganisationID group a by a.AssessmentQuestions.AssessmentQuestionGroups.QuestionGroup into g select new { Group = g.Key, Answer = g }; When i drill down into g,

pivot dataframe with duplicate values

六月ゝ 毕业季﹏ 提交于 2019-12-13 01:50:29
问题 consider the below pd.DataFrame temp = pd.DataFrame({'label_0':[1,1,1,2,2,2],'label_1':['a','b','c',np.nan,'c','b'], 'values':[0,2,4,np.nan,8,5]}) print(temp) label_0 label_1 values 0 1 a 0.0 1 1 b 2.0 2 1 c 4.0 3 2 NaN NaN 4 2 c 8.0 5 2 b 5.0 my desired output is label_1 1 2 0 a 0.0 NaN 1 b 2.0 5.0 2 c 4.0 8.0 3 NaN NaN NaN I have tried pd.pivot and wrangling around with pd.gropuby but cannot get to the desired output due to duplicate entries. any help most appreciated. 回答1: d = {} for _0,