group-by

MySQL GroupBy and Shows it horizontally

旧时模样 提交于 2020-08-27 09:11:07
问题 Supposed that I have table below: 1) tblScore ============================ Date VendorID Score ============================ 12/09/01 12001 A 12/09/01 12001 A 12/09/01 12002 B 12/09/02 12003 C 12/09/02 12003 A 12/09/03 12001 C ============================ I have this query: SELECT ts.VendorID, ts.Score, COUNT(*) FROM trxscore ts GROUP BY ts.VendorID, ts.Score ORDER BY ts.VendorID, ts.Score But how to show the table like: =========================== VendorID A B C ===========================

Why is Postgres not using index on a simple GROUP BY?

为君一笑 提交于 2020-08-24 10:14:52
问题 I have created a 36M rows table with an index on type column: CREATE TABLE items AS SELECT (random()*36000000)::integer AS id, (random()*10000)::integer AS type, md5(random()::text) AS s FROM generate_series(1,36000000); CREATE INDEX items_type_idx ON items USING btree ("type"); I run this simple query and expect postgresql to use my index: explain select count(*) from "items" group by "type"; But the query planner decides to use Seq Scan instead: HashAggregate (cost=734592.00..734627.90 rows

Pandas groupby: get size of a group knowing its id (from .grouper.group_info[0])

你。 提交于 2020-08-21 04:41:28
问题 In the following snippet data is a pandas.DataFrame and indices is a set of columns of the data . After grouping the data with groupby I am interested in the ids of the groups, but only those with a size greater than a threshold (say: 3). group_ids=data.groupby(list(data.columns[list(indices)])).grouper.group_info[0] Now, how can I find which group has a size greater than or equal 3 knowing the id of the group? I only want ids of groups with a certain size. #TODO: filter out ids from group