group-by

Filtering log file using COUNT, GROUP BY, ORDER BY MAX

为君一笑 提交于 2019-12-24 07:35:40
问题 Hi I have a machine that logs where guests and users navigate to and I'm trying to write a php script that will sort the logs and summarize for me the top five destinations people tend to go to i.e. what pages are visited the most. So far this is what I have: <?php #### mysql connection ##### $db = mysql_connect("_","guest","_"); mysql_select_db(networkr) or die("Couldn't select the database"); echo "<table>"; $query = "SELECT uri LIMIT 5, COUNT(date) GROUP BY uri ORDER BY MAX(COUNT(date)),

Show top N scores in MySQL 8 without duplicates by category

荒凉一梦 提交于 2019-12-24 07:27:05
问题 I have the following table in MySQL 8.0.15: CREATE TABLE golf_scores (person TEXT, score INT); INSERT INTO golf_scores VALUES ('Angela', 40),('Angela', 45),('Angela', 55),('Peter',45),('Peter',55),('Rachel', 65),('Rachel',75),('Jeff',75); SELECT * FROM golf_scores; +--------+-------+ | person | score | +--------+-------+ | Angela | 40 | | Angela | 45 | | Angela | 55 | | Peter | 45 | | Peter | 55 | | Rachel | 65 | | Rachel | 75 | | Jeff | 75 | +--------+-------+ I am trying to get the

c# linq MethodCallExpression for Sum( DataRow) used for .GroupedBy().Select()

百般思念 提交于 2019-12-24 07:04:18
问题 I programmed the following query which selects the grouped data key columns and sums the Amount column. It works perfect. private static IEnumerable<GroupSum> GetListOfGroupedRows(IEnumerable<IGrouping<GroupKey, DataRow>> queryGroup) { IEnumerable<GroupSum> querySelect = queryGroup .Select(g => new GroupSum { KeyS0 = g.Key.KeyS0, KeyS1 = g.Key.KeyS1, AggN0 = g.Sum(row => row.Field<double>("Amount")) }); return querySelect; } The query uses the following types to group and sum. private class

sorting error in union query

Deadly 提交于 2019-12-24 06:51:12
问题 SELECT DISTINCT rt . d_rev_id , rt . d_rev_code , rt . d_reason , rt . d_rev_status , rt . d_apb , rt . d_cb , pt . d_partid , pt . d_part_no , pt . d_ab , pt . d_abd , pt . d_status , rt . d_part_name , rt . d_part_desc , rt . d_part_type , pnv . d_pn_val , pnv . d_pn_id , cfv . d_optionname , rt . d_projectid , rt . d_abd , rt . d_apbd FROM ( ( design_parts pt INNER JOIN design_part_number_val pnv USING ( d_partid ) INNER JOIN design_revision_temp rt USING ( d_partid ) ) LEFT JOIN design_pn

sorting error in union query

 ̄綄美尐妖づ 提交于 2019-12-24 06:51:09
问题 SELECT DISTINCT rt . d_rev_id , rt . d_rev_code , rt . d_reason , rt . d_rev_status , rt . d_apb , rt . d_cb , pt . d_partid , pt . d_part_no , pt . d_ab , pt . d_abd , pt . d_status , rt . d_part_name , rt . d_part_desc , rt . d_part_type , pnv . d_pn_val , pnv . d_pn_id , cfv . d_optionname , rt . d_projectid , rt . d_abd , rt . d_apbd FROM ( ( design_parts pt INNER JOIN design_part_number_val pnv USING ( d_partid ) INNER JOIN design_revision_temp rt USING ( d_partid ) ) LEFT JOIN design_pn

Group linq results by value and group null or invalid values and do counts

寵の児 提交于 2019-12-24 06:37:15
问题 this is a follow on question to this question. I now would like to do some counts on the groupings. Original Query: that excluded invalid zip codes did the following: List<DataSourceRecord> md = (from rst in QBModel.ResultsTable where (!String.IsNullOrWhiteSpace(rst.CallerZipCode) && rst.CallerZipCode.Length > 2) group rst by rst.CallerZipCode.Substring(0, 3) into newGroup orderby newGroup.Key select new DataSourceRecord() { State = newGroup.Select(i => i.CallerState).FirstOrDefault(),

GroupBy two columns with margins for first level

北战南征 提交于 2019-12-24 06:00:40
问题 I am grouping a dataframe by 2 columns and i aggregate by the sum of the other columns. How I can have a total by the first grouped column in the same data frame? for example my data frame is: np.random.seed(0) df = pd.DataFrame({'A' : ['foo', 'bar', 'foo', 'bar', 'foo', 'bar', 'foo', 'foo'], 'B' : ['one', 'one', 'two', 'three', 'two', 'two', 'one', 'three'], 'C' : np.random.randn(8), 'D' : np.random.randn(8)}) The result of: grouped = df.groupby(by=['A', 'B']).sum() is: C D A B bar one 0

MySQL group rows to find time difference

社会主义新天地 提交于 2019-12-24 05:31:51
问题 I have car_history table, I need to find time difference between each car_status in selected date. e.g 1. to_load - 9 h. 2. to_load - 8 h. and so on... How I can find entries from id = 1 to id = 4 and id = 8 to id = 10 to count how log took to_load status. -------------------------------------------------------------------- | id | car_id | car_status | comments | entry_date | -------------------------------------------------------------------- | 1 | 1 | to_load | preparing | 2013-06-12 08:00

MySQL How to assign a null value to non matching columns when using Group By

断了今生、忘了曾经 提交于 2019-12-24 05:27:10
问题 I have the following MovieTheaterTbl table: Name Location Date TicketRevenue SnackRevenue BeverageRevenue AMC Alpine St. 8/14 100 80 60 Atlas Main St. 8/19 300 150 100 Atlas Lincoln Rd. 8/19 50 50 40 I would like to insert this data into a table called SummaryTbl, which should display the sum of the Revenue columns, grouped by the movie theater name. If any of the other columns are not identical for rows with the same name (for example the location differs in the 2 Atlas entries), I would

Using matplotlib boxplot with groupby

℡╲_俬逩灬. 提交于 2019-12-24 04:33:09
问题 I have what superficially appears to be a simple question, but I cannot find the answer. I have a feature in my df for which I would like to use groupby on two different categories. Here's my metacode: df = pd.DataFrame(np.random.rand(100,2), columns=['Col1', 'Col2'] ) # Assume each series below repeats. df['X'] = pd.Series(['A','B','A','B',...,'A','B','A','B']) df['Y'] = pd.Series(['X','Y','X','Y',...,'X','Y','X','Y']) How can I use groupby to create 4 box plotsfor a particular feature in