group-by

LINQ Grouping dynamically

时光总嘲笑我的痴心妄想 提交于 2020-01-08 12:31:09
问题 I have a class list of records, so user can select to group rows dynamically by property name. For example MenuText , RoleName or ActionName . Then I have to execute grouping so I need a generic method to handle grouping by passing column name. Example : public class Menu { public string MenuText {get;set;} public string RoleName {get;set;} public string ActionName {get;set;} } public class Menus { var list = new List<Menu>(); list.Add( new Menu {MenuText="abc",RoleName ="Admin", ActionName=

LINQ Grouping dynamically

。_饼干妹妹 提交于 2020-01-08 12:30:02
问题 I have a class list of records, so user can select to group rows dynamically by property name. For example MenuText , RoleName or ActionName . Then I have to execute grouping so I need a generic method to handle grouping by passing column name. Example : public class Menu { public string MenuText {get;set;} public string RoleName {get;set;} public string ActionName {get;set;} } public class Menus { var list = new List<Menu>(); list.Add( new Menu {MenuText="abc",RoleName ="Admin", ActionName=

2 GROUP BY WITH DISTINCT, SUM , COUNT: PHP MySQL

一个人想着一个人 提交于 2020-01-07 06:57:15
问题 Ref : GROUP BY WITH HAVING ( DISTINCT ) : PHP , MYSQL I got answer (thanks @coytech) but I need one more column in it: as per: id | mid | pid | owgh | nwgh | 1 3 12 1.5 0.6 2 3 12 1.5 0.3 3 3 14 0.6 0.4 4 3 15 1.2 1.1 5 4 16 1.5 1.0 6 4 17 2.4 1.2 7 3 19 3.0 1.4 I got answer Select mid , COUNT(distinct pid) as cpid , SUM(nwgh) as totalnwgh from test GROUP BY mid sqlfiddle : http://sqlfiddle.com/#!9/45e68/2 mid cpid totalnwgh 3 4 3.8 4 2 2.2 But above I need one more column that's as below :

Json data Match Fixtures Group by Pool number

假如想象 提交于 2020-01-07 05:45:33
问题 Further to this Question, Json data Group by value using php now i want to group the fixture by pool number Json Data is here { "items":[ {"id":129481,"draw_id":27718,"number":1,"pool":-1, "fixtures":[ {"id":"529348","name":"TBC vs TBC","round":{"id":129481,"number":1,"round_info":"PRE QUARTER FINALS","published":true},"match_result":null,"matches":[],"officials":[],"_score":null,"_type":"fixture"}, {"id":"529349","name":"TBC vs TBC","round":{"id":129481,"number":1,"round_info":"PRE QUARTER

CodeIgniter - order my 'posts' by month?

…衆ロ難τιáo~ 提交于 2020-01-07 05:05:33
问题 In my website I'd like to create an 'archive' list to categorise my posts. My posts table is set up like so: id | post_title | post | pubdate | year | month Currently this model function pulls the posts: function getNews(){ $data = array(); $this->db->order_by("id", "desc"); $Q = $this->db->get('posts'); if ($Q->num_rows() > 0){ foreach ($Q->result_array() as $row){ $data[] = $row; } } $Q->free_result(); return $data; } However, is it possible I can create a list like the following? July (12)

Same Query returns different results (MySQL Group By)

风流意气都作罢 提交于 2020-01-07 02:50:28
问题 This only happens for queries that force GROUP BY after ORDER BY . Goal: Get latest balance for each unit for the given cardID . Table: cardID | unit | balance | date --------|-----------|-----------|-------------- A1 | DEPOSIT | 100 | 2016-05-01 A1 | DEPOSIT | 90 | 2016-05-02 A1 | DEPOSIT | 80 | 2016-05-03 A1 | DEPOSIT | 75 | 2016-05-04 A1 | MINUTE | 1000 | 2016-05-01 A1 | MINUTE | 900 | 2016-05-02 A1 | MINUTE | 800 | 2016-05-03 Query: SELECT * FROM ( SELECT unit, balance FROM cardBalances

Random order for group of rows in mysql

南楼画角 提交于 2020-01-07 02:50:14
问题 maybe it´s easy but i have no clue how to handle this correctly. I have the following table t1 with this data: ----------------- | id | gr_id | ----------------- | 1 | a | | 2 | a | | 3 | b | | 4 | b | | 5 | c | | 6 | c | | 7 | d | | 8 | d | ----------------- I would like to get randomly gr_ids like this: ----------------- | id | gr_id | ----------------- | 3 | b | | 4 | b | | 5 | c | | 6 | c | | 7 | d | | 8 | d | | 1 | a | | 2 | a | ----------------- Getting ordered gr_ids ascend and descend

Select entry with maximum value of column after grouping

為{幸葍}努か 提交于 2020-01-07 02:43:34
问题 I currently got this query: SELECT `users_sessions`.`userid` `users_sessions`.`lastActive` , `users`.`firstname` FROM `users_sessions` , `users` WHERE `users_sessions`.`lastActive` >= DATE_SUB( NOW( ) , INTERVAL 60 MINUTE ) AND `users`.`uidNumber` = `users_sessions`.`userid` It selects all sessions where lastActive is 1 hour ago maximum. Now, as users can have multiple sessions at the same time, I only want to select the one with the biggest lastActive value. I know that I somehow got to use

JOIN two tables while grouping by an index and maching for multiple foreign ids

孤街醉人 提交于 2020-01-07 02:36:14
问题 I have the 3 Following Tables: objects: ObjectID ObjectDescription 1 "first" 2 "second" attributes: AttributeID AttributeDescription 1 "att1" 2 "att2" 3 "att3" 4 "att4" attributelink: AttributeID ObjectID 1 1 2 1 4 1 Now my question: I want now have some attributes selected and want to know, which Object has all my selected Attributes. I've tried the following: SELECT * FROM `objects` INNER JOIN `attributelink` ON `objects`.`ObjectID` = `attributelink`.`ObjectID` WHERE `attributelink`.

mySQL: sum by a different group-by

强颜欢笑 提交于 2020-01-07 02:23:27
问题 I have a table: (Edited with x5) _date(2014-03-05;2014-04-05) _period(1,2,3,4,5,1,2,3,4,5,1,2; 1,2,3,4,5,1,2,3,4,5) _id(x1,x1,x1,x1,x1,x2,x2,x2,x2,x2,x3,x3;x4,x4,x4,x4,x4,x5,x5,x5,x5,x5) _reading(1,1,1,1,1,2,2,2,2,2,5,6;1,1,1,1,1,2,1,1,1,1) _reading2 (5,5,5,5,5,4,4,4,4,4,7,7;1,1,1,1,1,1,1,1,1,1) image of the table 1 i need a result like below which eliminates all data which doesn't have full period 1 to 5 for the _id, then calculates the sum of _reading for a day and sum of _reading2 for each