group-by

Populate group data to a particular series on Highcharts

邮差的信 提交于 2019-12-20 04:22:22
问题 Trying to group tow columns and and populate it as a particular series on highcharts. my code not grouping columns, And showing all data as a single series. $query = $db->Prepare("SELECT class, SUM(marks), DATE(date_column) as dates FROM classes GROUP BY class,DATE(date_column)"); $query->execute(); while ( $row = $query->fetch(PDO:: FETCH_ASSOC)) { $date = $row['dates']; $dates[] = $row['dates']; $class[] = $row['class']; $marks[] = $row['SUM(marks)']; $output[] = array($date,(int)$marks); }

How can I modify this query with two Inner Joins so that it stops giving duplicate results?

ぐ巨炮叔叔 提交于 2019-12-20 04:09:23
问题 EDIT: I will leave the post here as is, but what I really needed to accomplish needed to be reposted. I didn't explain the problem well enough. After trying again with quite a different starting point, I was able to get the query that I needed. That is explained here. ORIGINAL QUESTION: I'm having trouble. I have looked at similar threads, and I am unable to find a solution specific to this query. The database is very large, and group by seems to slow it down immensely. The problem is I am

MySQL GROUP & COUNT Multiple tables

蹲街弑〆低调 提交于 2019-12-20 03:52:23
问题 I have a 3 part problem thats been giving me trouble I know how to get the tables to work if I query 1 table at a time but I can't seem to figure out how I can combine both the tags and more_tags tables to get the same results. The 3 main problems I have are Listed below. PROBLEM 1 I want to be able to group the same tag from both the tags and more_tags tables. PROBLEM 2 I also want to be able to display the tags from each table that are not present in the other table. PROBLEM 3 I also want

How do I get the record ID of the record with the min date for each foreign key?

丶灬走出姿态 提交于 2019-12-20 03:45:07
问题 I have the following table recordID createdDate ForeignKeyID 00QA000000PtFXaMAN 2012-01-03 13:23:36.000 001A000000ngM21IAE 00QA000000OS2QiMAL 2011-12-15 12:03:02.000 001A000000ngM21IAE . . . . I am trying to get the recordID for foreignKeyID where createdDAte is the min(createdDate) for foreignKeyID if recordID is identity int I can get that by doing the following query Select min(recordId),ForeignkeyID from table group by ForeignKeyId I originaly thought that I can create temp table with the

T-SQL Dynamic GROUP BY using @parameters

百般思念 提交于 2019-12-20 03:36:12
问题 I would like to achieve SELECT @param1, @param2, @param3, t.field1, sum(t.amount) FROM table t WHERE t.field 2 IS NOT NULL AND t.field3ID = '12345' GROUP BY @param1, @param2, @param3 What is the best approach? Is building dynamic SQL is the way to go? 回答1: Dynamic SQL is the only way to go here. However, what kind of table do you have where you have a bunch of optional grouping columns? 回答2: First of all t.field1 should also be in your group by or handled in the sql with an aggrigate function

How to extract numeric ranges from 2 columns containig numeric sequences and print the range from both columns (different increment values)?

ε祈祈猫儿з 提交于 2019-12-20 03:32:14
问题 I'm curently learnig python and pandas (this question is based on a pevious post but with an additional query); at the moment have the 2 columns containing numeric sequences (ascending and/or descending) as described below: Col 1: (col1 numeric incrememt and/or decrement = 1) 1 2 3 5 7 8 9 Col 2: (Col2 numeric increment and/or decrement = 4) 113 109 105 90 94 98 102 Need to extract the numeric ranges from both columns and print them according to the sequence break occurance on any of those 2

MySQL combining COUNT, MAX and SUM

这一生的挚爱 提交于 2019-12-20 03:21:34
问题 In MySQL, I would like to have an extra column showing the sum of values of a particular column. However, the numbers I would like to sum come from a subquery and are not stored in a separate table, something like this: (SELECT a.ID, MAX(a.COUNT_ID) AS MAX_COUNT FROM (SELECT ID, COUNT(*) AS COUNT_ID FROM my_table GROUP BY COL1, COL2) a GROUP BY COL1, COL2) b And this would output something like: ID MAX_COUNT ABC 1 DEF 2 GHI 3 And now, I want an extra column showing the sum of MAX_COUNT, like

MySQL only get overall ROLLUP

做~自己de王妃 提交于 2019-12-20 02:43:12
问题 Performing a WITH ROLLUP when grouping by multiple fields, MySQL returns a rollup row for each group, as well as the overall summary: CREATE TABLE test (name VARCHAR(50), number TINYINT); INSERT INTO test VALUES ('foo', 1), ('foo', 1), ('foo', 2), ('foo', 3), ('foo', 3), ('bar', 1), ('bar', 2), ('bar', 2), ('bar', 2), ('bar', 3), ('baz', 1), ('baz', 2), ('bar', 2); SELECT name, number, COUNT(1) FROM test GROUP BY name, number WITH ROLLUP; +------+--------+----------+ | name | number | count(1

Sum top 5 values in MySQL

人走茶凉 提交于 2019-12-20 01:57:46
问题 I have a MySQL table where I store results from a racing championship, so that every rows contains -among other data- every driver's position in a certain race. I want to get the sum of a certain driver's top 5 placings (for instance, if a driver's best positions were 1,2,2,4,5, I'd like MySQL to return 14). What I'm trying to do is this: SELECT driver, SUM(position) FROM results WHERE (race, season, position) IN (SELECT race, season, position FROM results WHERE driver = "Vettel" ORDER BY

Multiple aggregation in group by in Pandas Dataframe

杀马特。学长 韩版系。学妹 提交于 2019-12-20 01:53:07
问题 SQL : Select Max(A) , Min (B) , C from Table group by C I want to do the same operation in pandas on a dataframe. The closer I got was till : DF2= DF1.groupby(by=['C']).max() where I land up getting max of both the columns , how do i do more than one operation while grouping by. 回答1: try agg() function: import numpy as np import pandas as pd df = pd.DataFrame(np.random.randint(0,5,size=(20, 3)), columns=list('ABC')) print(df) print(df.groupby('C').agg({'A': max, 'B':min})) Output: A B C 0 2 3