group-by

SQL Get X last entries from a 'custom' post_type counting users individual number of custom post_type

你离开我真会死。 提交于 2019-12-24 02:07:14
问题 I would like, if possible to get in one query: The last 4 different users Excluding 'ID' = '1' WITH post_type = 'custom' Ordered by date or ID ( DESC ) Counting the total number of 'custom' post_type for each user (COUNT()) Here is a data example: Table Name: 'post' ID | user | Date | title | status | post_type | | | | | "2785" | "1" | "2016-05-24 18:49:15" | "Title" | "published" | "page_post" "2783" | "5" | "2016-05-24 11:24:08" | "Title" | "published" | "custom" "2781" | "1" | "2016-05-18

MySQL 'group by' with 'left join' throws away some entries

泄露秘密 提交于 2019-12-24 01:59:11
问题 I have a query that looks something like this: SELECT orders.order_id, items.item_id, GROUP_CONCAT(graphics.graphic_id) AS graphic_ids FROM orders orders LEFT JOIN order_items items ON orders.order_id = items.order_id LEFT JOIN order_graphics graphics on graphics.item_id = items.item_id WHERE // etc GROUP BY items.item_id Orders can have zero or more items, and items can have zero or more graphics. The goal is to get all orders matching the WHERE condition, itemize them by order item, and

MySQL SUM when using GROUP BY not working

余生长醉 提交于 2019-12-24 01:54:46
问题 Let's say we have this table: Symbol | Size A | 12 B | 5 A | 3 A | 6 B | 8 And we want a view like this: Symbol | Size A | 21 B | 13 So we use this: Select Symbol, sum(Size) from table group by Symbol order by Symbol ASC But instead we get this: Symbol | Size A | 12 B | 5 What am I doing wrong?! 回答1: You are doing it right, you should expect the correct results. Could you please supply more information about the DB you are using, additional schemas, etc? Maybe you have some unique index on

Sorting and ranking by dates, on a group in a pandas df

社会主义新天地 提交于 2019-12-24 01:38:15
问题 From the following sort of dataframe I would like to be able to both sort and rank the id field on date: df = pd.DataFrame({ 'id':[1, 1, 2, 3, 3, 4, 5, 6,6,6,7,7], 'value':[.01, .4, .2, .3, .11, .21, .4, .01, 3, .5, .8, .9], 'date':['10/01/2017 15:45:00','05/01/2017 15:56:00', '11/01/2017 15:22:00','06/01/2017 11:02:00','05/01/2017 09:37:00', '05/01/2017 09:55:00','05/01/2017 10:08:00','03/02/2017 08:55:00', '03/02/2017 09:15:00','03/02/2017 09:31:00','09/01/2017 15:42:00', '19/01/2017 16:34

Can I add same object to multiple groups in LINQ?

懵懂的女人 提交于 2019-12-24 01:03:06
问题 I have a set of objects I want to group in Linq. However the key I want to use is a combination of multiple keys. for eg Object1: Key=SomeKeyString1 Object2: Key=SomeKeyString2 Object3: Key=SomeKeyString1,SomeKeyString2 Now I'd like the results to be only two groups Grouping1: Key=SomeKeyString1 : Objet1, Object3 Grouping2: Key=SomeKeyString2 : Object2, Object3 Basically I want the same object to be part of two groups. Is that possible in Linq? 回答1: Well, not directly with GroupBy or

PHP SimpleXML Group By Element Type

荒凉一梦 提交于 2019-12-24 00:52:32
问题 Ok here's my dilemma. I am looking for a way to consolidate the data in a group using SimpleXML in PHP . Here's what I mean. Let's say I have an xml that looks like this: <favorites> <interesting> <type>Movie</type> <character>James Bond</character> <name>Casino Royale</name> </interesting> <interesting> <type>Movie</type> <character>Jason Bourne</character> <name>Bourne Identity</name> </interesting> <interesting> <type>Book</type> <character>Lindsay Ford</character> <name>Shantaram</name> <

group by month and year parts using queryover

自作多情 提交于 2019-12-24 00:41:01
问题 I have a model, that contains a DateTime field and a Price field. I want to get a list that gives me an aggregation of month/year - price so for the data: 15/01/2012 200 16/01/2012 200 15/02/2012 300 16/02/2012 300 15/03/2012 400 16/03/2012 400 I will get: 01/2012 400 02/2012 600 03/2012 800 So far I didn't find a way to achive this using QueryOver. I keep getting "could not resolve property" when i try to look at the Month/Year parts of the date. Those questions: Group posts by year, then by

How to make new columns by counting up an existing column

荒凉一梦 提交于 2019-12-24 00:40:00
问题 I'd like to make some other columns by doing group_by in R. When the original table is like below userID cat1 cat2 a f 3 a f 3 a u 1 a m 1 b u 2 b m 1 b m 2 I group them by userID and want it come like userID cat1_f cat1_m cat1_u cat2_1 cat2_2 cat2_3 a 2 1 1 2 0 1 b 0 2 1 1 2 0 回答1: We could gather all the values then count them, create a new column by paste ing cat and value values and then spread it back to wide format with fill=0 . library(tidyverse) df %>% gather(cat, value, -userID) %>%

df ['X'].unique() and TypeError: unhashable type: 'numpy.ndarray'

橙三吉。 提交于 2019-12-24 00:38:54
问题 all, I have a column in a dataframe that looks like this: allHoldingsFund['BrokerMixed'] Out[419]: 78 ML 81 CITI 92 ML 173 CITI 235 ML 262 ML 264 ML 25617 GS 25621 CITI 25644 CITI 25723 GS 25778 CITI 25786 CITI 25793 GS 25797 CITI Name: BrokerMixed, Length: 2554, dtype: object Although the column is an object. I am not able to group by that column or even extract the unique values of that column. For example when I do: allHoldingsFund['BrokerMixed'].unique() I get an error uniques = table

Optimize sub-query selecting last record of each group

自闭症网瘾萝莉.ら 提交于 2019-12-24 00:16:25
问题 I have this query which is a dependant query and taking much execution time SELECT u.id, u.user_name, ifnull((select longitude from map where user_id = u.id order by map_id desc limit 1 ),0) as Longitude, ifnull((select latitude from map where user_id = u.id order by map_id desc limit 1 ),0) as Longitude, (select created from map where user_id = 1 order by created desc limit 1) as LatestTime FROM users as u WHERE id IN(SELECT user1_id FROM relation WHERE users.id = 1) ORDER BY id; I tried