group-by

Group by ID and Order by date

会有一股神秘感。 提交于 2019-12-20 06:32:58
问题 $lastComments = $this->Comment->find('all', array('fields' => array('Comment.news_id', 'Comment.date', 'Comment.content'), 'group' => array('Comment.news_id, Comment.date'), 'order' => array('Comment.date DESC')) ); The idea is to get latest comment from unique topics (1 comment - 1 topic). This code doesn't handle unique ID's (unique topics), how Can I fix that? Distinct doesn't work. $lastComments = $this->Comment->find('all', array('fields' => array('Comment.news_id', 'Comment.date',

How to show the maximum number for each combination of customer and product in a specific state in Postgresql?

故事扮演 提交于 2019-12-20 06:26:27
问题 I just begin learning Postgresql recently. I have a table named 'sales': create table sales ( cust varchar(20), prod varchar(20), day integer, month integer, year integer, state char(2), quant integer ) insert into sales values ('Bloom', 'Pepsi', 2, 12, 2001, 'NY', 4232); insert into sales values ('Knuth', 'Bread', 23, 5, 2005, 'PA', 4167); insert into sales values ('Emily', 'Pepsi', 22, 1, 2006, 'CT', 4404); insert into sales values ('Emily', 'Fruits', 11, 1, 2000, 'NJ', 4369); insert into

Top Group By DB2

自作多情 提交于 2019-12-20 05:26:13
问题 I've been trying for hours but can't get the query to do what I want using DB2. From table Company and Users I have the following tickets quantity info per company/user user company quantity ------------ ------------ ------------ mark nissan 300 tom toyota 50 steve krysler 80 mark ford 20 tom toyota 120 jose toyota 230 tom nissan 145 steve toyota 10 jose krysler 35 steve ford 100 This is generated by the query: SELECT T.USER, COUNT(T.USER) AS QUANTITY, T.COMPANY FROM TICKET T INNER JOIN

ORA-00979: not a GROUP BY expression [duplicate]

浪尽此生 提交于 2019-12-20 04:44:05
问题 This question already has answers here : ORA-00979 not a group by expression (8 answers) Closed 4 years ago . I am trying show all the different companies for which students work. However only companies where more than four students are employed should be displayed. This is what I have so far: SELECT EMPLOYER, COUNT (STUDENT_ID) FROM STUDENT GROUP BY STUDENT_ID HAVING COUNT (STUDENT_ID) >4; I keep getting this message: ERROR at line 1: ORA-00979: not a GROUP BY expression I don't get it. I

Sum set of values from pandas dataframe within certain time frame

亡梦爱人 提交于 2019-12-20 04:41:19
问题 I have a fairly complicated question. I need to select rows from a data frame within a certain set of start and end dates, and then sum those values and put them in a new dataframe. So I start off with with data frame, df : import random dates = pd.date_range('20150101 020000',periods=1000) df = pd.DataFrame({'_id': random.choice(range(0, 1000)), 'time_stamp': dates, 'value': random.choice(range(2,60)) }) and define some start and end dates: import pandas as pd start_date = ["2-13-16", "2-23

Sum set of values from pandas dataframe within certain time frame

时光毁灭记忆、已成空白 提交于 2019-12-20 04:41:07
问题 I have a fairly complicated question. I need to select rows from a data frame within a certain set of start and end dates, and then sum those values and put them in a new dataframe. So I start off with with data frame, df : import random dates = pd.date_range('20150101 020000',periods=1000) df = pd.DataFrame({'_id': random.choice(range(0, 1000)), 'time_stamp': dates, 'value': random.choice(range(2,60)) }) and define some start and end dates: import pandas as pd start_date = ["2-13-16", "2-23

Attempting to find the 5 largest values per month using groupby

喜你入骨 提交于 2019-12-20 04:34:24
问题 I am attempting to show the top three values of nc_type for each month. I tried using n_largest but that doesn't do it by date. Original Data: area nc_type occurred_date 0 Filling x 12/23/2015 0:00 1 Filling f 12/22/2015 0:00 2 Filling s 9/11/2015 0:00 3 Filling f 2/17/2016 0:00 4 Filling s 5/3/2016 0:00 5 Filling g 8/29/2016 0:00 6 Filling f 9/9/2016 0:00 7 Filling a 6/1/2016 0:00 Transformed with: df.groupby([df.occurred_date.dt.month, "nc_type"])["rand"].count() Transformed Data: occurred

mySQL count only returning one result unless using group by

旧时模样 提交于 2019-12-20 04:30:20
问题 using the SQL query select u.name,count(u.name) as 'followers' from user u,follow f where u.type = 'c' AND f.followee = u.email group by u.name gets me the correct value for all users in my database, however, the exact same query without the group by line only gives me the first value. I am learning SQL for the first time and was having a hard time figuring out why this is. 回答1: When you use count without group by it will count all the records and returns single line while when you use count

sql having get only the first recorded row in table and i want all

こ雲淡風輕ζ 提交于 2019-12-20 04:26:06
问题 Somebody already helped me with this query but I made an adaptation and I get a problem : SELECT AVG(tyd.price) AS avg_price, COUNT(tyd.id_product) AS cnt, tyd.id_marchand, tyd.id_product, catalog.price AS c_price, tyd.price AS t_price, tyd.amount AS t_am, pro_tyd.amount AS p_am, pro_tyd.price AS p_price, catalog.img_src, tyd.step, tyd.login AS tyd_l FROM catalog INNER JOIN tyd ON catalog.id_marchand = tyd.id_marchand AND catalog.id_product = tyd.id_product AND tyd.step = "1" INNER JOIN pro

How to divide the dataframe in pandas into multiple dataframes based on the group by results?

蓝咒 提交于 2019-12-20 04:24:22
问题 Date_A Date_B Date_C Amount 0 09/01/2016 09/01/2016 01/01/1800 2405814.36 1 09/01/2016 09/01/2016 09/01/2016 11347445.71 2 09/01/2016 10/01/2016 01/01/1800 5005106.94 3 09/01/2016 10/01/2016 09/02/2016 391679.95 4 09/01/2016 10/01/2016 10/01/2016 15982401.76 5 09/01/2016 11/01/2016 01/01/1800 3625649.29 6 09/01/2016 11/01/2016 10/14/2016 200730.30 7 09/01/2016 11/01/2016 11/01/2016 3801867.77 8 09/01/2016 01/01/2017 01/01/2017 398961.22 9 10/01/2016 10/01/2016 01/01/1800 1357447.92 10 10/01