group-by

SQL Group BY using strings in new columns

风格不统一 提交于 2019-12-24 04:04:26
问题 I have a database of race results. Each race event has multiple classes. events table: event_id | event_date ---------+------------ 1 | 11/5/14 2 | 11/12/14 3 | 11/19/14 results table: result_event | name | class | position -------------+---------------+-------+----------- 1 | Jason Smith | 40 | 1 1 | David Johnson | 40 | 2 1 | Randy White | 30 | 1 1 | Billy Hansen | 30 | 2 2 | Wally Mann | 40 | 1 2 | Shawn Little | 40 | 2 2 | Eric Davis | 30 | 1 2 | Tom Handy | 30 | 2 I want to create a

How to Get A Count From Another Table In SQL?

我的梦境 提交于 2019-12-24 04:02:21
问题 I have the following tables on SQL: Mensajes IdMensaje (int) PK NOT NULL IdCliente (int) CorreoCliente (varchar(100)) CorreosAdicionales (varchar(MAX)) Tema (varchar(100)) Mensaje (varchar(MAX)) Fecha (date) Hora (time(5)) Archivos IdArchivo (int) PK NOT NULL IdMensaje (int) Nombre (varchar(200)) Foreign Key Mensajes.IdMensaje ON Archivos.IdMensaje If you are wondering what Mensajes.IdCliente is, yes, it has a foreign key with another table but that's another story First an intro... I'm

Select Sum from two joined tables

99封情书 提交于 2019-12-24 04:01:40
问题 There are structures: CREATE TABLE `invoices` ( `id` int(10) unsigned NOT NULL AUTO_INCREMENT, `date` date NOT NULL, PRIMARY KEY (`id`) ) ENGINE=InnoDB; INSERT INTO `invoices` VALUES (1,'2018-09-22'); CREATE TABLE `products` ( `id` int(10) unsigned NOT NULL AUTO_INCREMENT, `invoice_id` int(10) unsigned NOT NULL, `amount` decimal(10,2) unsigned NOT NULL, `quantity` smallint(5) unsigned NOT NULL, PRIMARY KEY (`id`) ) ENGINE=InnoDB; INSERT INTO `products` VALUES (1,1,150.00,2),(2,1,60.00,3),(3,1

How to combine ';'.join and lambda x: x.tolist() inside an groupby.agg() function?

僤鯓⒐⒋嵵緔 提交于 2019-12-24 03:51:34
问题 Update down below! I am trying to merge and sort a list of IDs and their connected unique Name_ID, separated by semicolons. For example: Name_ID Adress_ID Name_ID Adress_ID Name1 5875383 Name1 5875383; 5901847 Name1 5901847 Name2 5285200 Name2 5285200 to Name3 2342345; 6463736 Name3 2342345 Name3 6463736 This is my current code: origin_file_path = Path("Folder/table.xlsx") dest_file_path = Path("Folder/table_sorted.xlsx") table = pd.read_excel(origin_file_path) df1 = pd.DataFrame(table) df1 =

How to combine ';'.join and lambda x: x.tolist() inside an groupby.agg() function?

我们两清 提交于 2019-12-24 03:51:05
问题 Update down below! I am trying to merge and sort a list of IDs and their connected unique Name_ID, separated by semicolons. For example: Name_ID Adress_ID Name_ID Adress_ID Name1 5875383 Name1 5875383; 5901847 Name1 5901847 Name2 5285200 Name2 5285200 to Name3 2342345; 6463736 Name3 2342345 Name3 6463736 This is my current code: origin_file_path = Path("Folder/table.xlsx") dest_file_path = Path("Folder/table_sorted.xlsx") table = pd.read_excel(origin_file_path) df1 = pd.DataFrame(table) df1 =

linq group by object

假装没事ソ 提交于 2019-12-24 03:39:38
问题 I have an object which contains a list of another object as follow: class cl { List<a> a ; public List<a> listofA { get; set; } } class a { //other properties string comment ; public string comment { get; set; } } Now how do i make a linq query to see if comment is of some string here is my query: var query = (from c in scope.Extent<cl>() where c.Date >= dateFrom && c.Date < dateTo && c.Actions.Where(a => (a.comment== "") ) orderby c.Date.Value.Date group c by c.Date.Value.Date into grpDate

How to get other columns with are not in GROUP BY clause in a oracle select sql?

依然范特西╮ 提交于 2019-12-24 02:49:07
问题 I have a table MOVIE containing this data. MOVIE_ID MOVIE_TITLE CATEGORY SALES_AMT --------- ------------------------ --------------- ---------- M_0000004 The Boss Baby Animation 2000 M_0000006 Star Wars: The Last Jedi Science Fiction 3000 M_0000007 Get Out Horror 4000 M_0000008 Million Dollar Arm Action 2000 M_0000009 The Conjuring Horror 1000 M_0000012 The Dark Knight Action 3000 I need the Top movies data based on SALES_AMT with respect to CATEGORY The required result is this: MOVIE_ID

How to use GROUP BY after the Having clause Mysql

我的梦境 提交于 2019-12-24 02:42:59
问题 Here is the query which gets the accounts for a specific user the products are related to accounts in one-to-many relation so for each product there are four permissions All the accounts which is not Disable and also shows their permissions I got all accounts according to scenario but the problem is if one account has more than one products then it obviously shows account id more than one time * What i am looking for to GROUP BY the a.id after the HAVING clause which checks the permissions *

Pandas: compute the mean of a column grouped by another column

让人想犯罪 __ 提交于 2019-12-24 02:18:32
问题 Say I have a dataframe like this: gender height weight C 2000-01-01 male 42.849980 157.500553 1 2000-01-02 male 49.607315 177.340407 1 2000-01-03 male 56.293531 171.524640 1 2000-01-04 female 48.421077 144.251986 2 2000-01-05 male 46.556882 152.526206 2 2000-01-06 female 68.448851 168.272968 1 2000-01-07 male 70.757698 136.431469 2 2000-01-08 female 58.909500 176.499753 3 2000-01-09 female 76.435631 174.094104 3 2000-01-10 male 45.306120 177.540920 2 How could I compute the mean of the height

Count email type per customer id

烂漫一生 提交于 2019-12-24 02:09:44
问题 I have a form that people can use to send emails to our clients. The user has an option to select between two canned messages (Message "1" or Message "2"). Behind the scenes, every time they hit the "SEND" button it logs into a "RECORDS" table (so long as it makes it through the error handlers). Let's pretend the RECORDS table has 2 columns: CUST_ID EMAIL_NUM 0000 1 0000 2 0000 1 0000 1 0001 2 0002 1 0002 1 0003 2 0003 2 0003 2 I need a query that counts the ones and twos for each CUST_ID. So