group-by

LINQ GroupBy on multiple ref-type fields; Custom EqualityComparer

限于喜欢 提交于 2019-12-31 03:40:51
问题 So I've looked through about 20 examples on this on SO and elsewhere, but haven't found one which covers what I'm trying to do. This - Can I specify my explicit type comparator inline? - looks like what I need, but doesn't go far enough (or I don't understand how to take it further). I have a List of LoadData, the LoadData object has fields of both reference and value types Need to group on a mixture of ref and value fields, project the output to an anonymous type Need (I think) to provide a

array_agg group by and null

只谈情不闲聊 提交于 2019-12-31 03:11:31
问题 Given this table: SELECT * FROM CommodityPricing order by dateField "SILVER";60.45;"2002-01-01" "GOLD";130.45;"2002-01-01" "COPPER";96.45;"2002-01-01" "SILVER";70.45;"2003-01-01" "GOLD";140.45;"2003-01-01" "COPPER";99.45;"2003-01-01" "GOLD";150.45;"2004-01-01" "MERCURY";60;"2004-01-01" "SILVER";80.45;"2004-01-01" As of 2004, COPPER was dropped and mercury introduced. How can I get the value of (array_agg(value order by date desc) ) [1] as NULL for COPPER ? select commodity,(array_agg(value

SQL Server Select the most recent record only

梦想与她 提交于 2019-12-30 11:56:12
问题 I have a table tat looks like this: Table1 ID Date TermDate Cancel 1 20140101 99999999 20140102 1 20140101 20130102 20140102 2 20140108 20130102 20140102 2 20140101 99999999 20140102 3 20140101 99999999 20140102 3 20140101 99999999 20140102 3 20140101 99999999 20140709 What I want to do is, to group by each ID and select only the most recent record. First I need to check the Date column, from there if a record is more recent then I do not need to check the other columns, in this case, it is

Mysql Update with table joins - update one table's field with sum of other table's field

ぃ、小莉子 提交于 2019-12-30 11:54:10
问题 I have two tables Orders and Order_Details Order_Details tables's order_id field acts as foreign key to Orders table's id_order table. I want to update the price_total field of Orders table with summation of prices from Order_Details table. I tried with the following query but failed:- Update Orders, Order_Details SET Orders.price_total = sum(Order_Details.price) WHERE Orders.price_total=0 GROUP BY Order_Details.id_order Error - #1064 - You have an error in your SQL syntax; check the manual

Get the last entries using GROUP BY

耗尽温柔 提交于 2019-12-30 10:59:15
问题 I'm having problem with GROUP BY. It returns the first entry it could find, but I would like it to return the last entry. Is that possible? Here is my query (prepared query): SELECT stamp_user, stamp_date, stamp_type FROM rws_stamps WHERE stamp_date >= ? GROUP BY stamp_user ORDER BY stamp_date DESC My table looks like this: What I want it to return is row 7 and 3, but i get 1 and 2. 回答1: Try: SELECT stamp_user, max(stamp_date), stamp_type FROM rws_stamps WHERE stamp_date >= ? GROUP BY stamp

DB2 Distinct + xmlagg Query

只愿长相守 提交于 2019-12-30 10:57:25
问题 I want equivalent to GROUP_CONCAT functionality of MySql in DB2. I have tried XML Aggrigate functon of DB2 for cocating murows. SELECT a.ID, substr(xmlserialize(xmlagg(xmltext( concat(',', SPECIALISATION)))as varchar( 1024 )),2), substr(xmlserialize(xmlagg(xmltext(concat(',,, BASIC_SKILL2)))as varchar( 1024 )),2), substr(xmlserialize(xmlagg(xmltext(concat(',', BASIC_SKILL1)))as varchar( 1024 )),2) FROM candidate_resume_data a,candidate_skills_info b,skill_special_master c,skill_master_basic2

PostgreSQL use value from previous row if missing

江枫思渺然 提交于 2019-12-30 10:09:09
问题 I have a following query: WITH t as ( SELECT date_trunc('hour', time_series) as trunc FROM generate_series('2013-02-27 22:00'::timestamp, '2013-02-28 2:00', '1 hour') as time_series GROUP BY trunc ORDER BY trunc ) SELECT DISTINCT ON(trunc) trunc, id FROM t LEFT JOIN ( SELECT id, created, date_trunc('hour', created) as trunc_u FROM event ORDER BY created DESC ) u ON trunc = trunc_u which yields the following result: "2013-02-27 22:00:00"; "2013-02-27 23:00:00";2 "2013-02-28 00:00:00";5 "2013

Calculate the number of occurrences of a specific event in the past AND future with groupings

a 夏天 提交于 2019-12-30 10:04:19
问题 this question is a modification of a problem I posted here where I have occurrences of a specific type on different days, but this time they are assigned to multiple users, for example: df = data.frame(user_id = c(rep(1:2, each=5)), cancelled_order = c(rep(c(0,1,1,0,0), 2)), order_date = as.Date(c('2015-01-28', '2015-01-31', '2015-02-08', '2015-02-23', '2015-03-23', '2015-01-25', '2015-01-28', '2015-02-06', '2015-02-21', '2015-03-26'))) user_id cancelled_order order_date 1 0 2015-01-28 1 1

Not a GROUP BY expression error [duplicate]

╄→尐↘猪︶ㄣ 提交于 2019-12-30 09:46:10
问题 This question already has answers here : ORA-00979 not a group by expression (8 answers) Closed 5 years ago . I'm relatively new to databases. I am using Oracle and I'm trying to implement this query to find the number of personal training sessions the member has had. The tables are; MEMBERS MEMBERS_ID(NUMBER), MEMBERSHIP_TYPE_CODE(VARCHAR), ADDRESS_ID(NUMBER), CLUB_ID(NUMBER) MEMBER_NAME(VARCHAR), MEMBER_PHONE(VARCHAR), MEMBER_EMAIL(VARCHAR) PERSONAL_TRAINING_SESSIONS SESSION_ID(VARHCAR),

Group Users by Age Range in ruby

三世轮回 提交于 2019-12-30 09:32:32
问题 I'm trying to list the number of users by age-range: Range : #Users 10-14 : 16 15-21 : 120 22-29 : 312 30-40 : 12131 41-70 : 612 71-120 : 20 I was thinking of creating a static array of hashes: AGE_RANGES = [ {label:"10 - 14", min:10, max:14}, {label:"15 - 21", min:15, max:21}, {label:"22 - 29", min:22, max:29}, {label:"30 - 40", min:30, max:40}, {label:"41 - 70", min:41, max:70}, {label:"71 - 120", min:71, max:120} ] and then use it for my search filter, as well as for my query. But, I