group-by

Laravel Display a record details while grouped by year or month

女生的网名这么多〃 提交于 2019-12-24 13:12:31
问题 I just moved to the laravel framework and am starting to migrate some legacy sites and I have hit a problem with SQL or blade - dunno which. I have to display a load of rows 'sports classes' which are grouped by year and then month. each needs to show attendance etc. I am unsure which way to proceed. I am able to display all rows and sort by date - easy squeezy I am able to groupBy year AND month - fiddly but sorted it. These are all displayed in an accordian. Click the month - the individual

Twig foreach group by date

寵の児 提交于 2019-12-24 13:00:25
问题 I have a table with football matches called 'matches'. In that table there is a field 'kickoff', which is a datetime-column of the time when the match starts. With the following code I get all the matches out of the table. $matches = $em->createQueryBuilder() ->select('m') ->from('FootballWcBundle:Matches', 'm') ->addOrderBy('m.kickoff', 'ASC') ->getQuery() ->getResult(); return $this->render('FootballWcBundle:Page:matches.html.twig', array( 'matches' => $matches )); Now I want to show the

Laravel Query Buider Group By Not Getting All The Records

扶醉桌前 提交于 2019-12-24 11:37:15
问题 I am trying to get the data using groupBy on type field from my transaction table. I am using this query DB::table($this->table) ->select() ->whereRaw($where['rawQuery'], isset($where['bindParams']) ? $where['bindParams'] : array()) ->groupBy('type') ->get(); But it is not giving the complete records . There are more than 10 records in my table. But it is giving me only two. One for type=1 and another for type=2. It is selecting only on record from each type. I am expecting that i will get

Couting combinations within a group

 ̄綄美尐妖づ 提交于 2019-12-24 11:34:27
问题 I need a way way to count combinations of code by patients, so I need to know based on this report total duration of each Service Program Protocol, so based on the picture below I need it to be like this Patient: 00000036 Adult CSS IND 240 Adult OP IND 120 Patient: 00000040 Adult CSS IND 420 Adult OP IND 60 I am using Microsoft SQL Server 2005 and I would prefer a fix in SQL, but if it could be done in crystal I could work with that. Thank you in advance. select pct.patient_id, pct.clinic_id,

Grouping rows with Groupby and converting date & time of rows of start date-time and end date- time columns

风格不统一 提交于 2019-12-24 11:18:24
问题 I have a dataset looking like this: Blast Hole East Coordinate North Coordinate Collar Theoritical Depth Tag Detector ID Date and Time Detection_Location Detection Date & Time 64 16745.42 107390.32 2634.45 15.95 385656531 23-08-2018 2:39:34 PM CV23 2018-09-08 14:18:17 61 16773.48 107382.6 2634.68 16.18 385760755 23-08-2018 2:38:32 PM CV23 2018-09-08 14:24:19 63 16755.07 107387.68 2634.58 16.08 385262370 23-08-2018 2:39:30 PM CV23 2018-09-08 14:12:42 105 16764.83 107347.67 2634.74 16.24

Linq: Split list by condition and max size of n

不问归期 提交于 2019-12-24 11:14:14
问题 I want to transform an array: ["a", "b", "b", "a", "b", "a", "b"] to ["a", "a", "b", "b", "a", "b", "b"] or ["b", "b", "a", "a", "b", "b", "a"] I want to group the array in a way where a special condition matches. In my case when item == 'a' or item == 'b' . And these groups I want to chunck into groups of 2. I'm currently a bit confused how to do it the elegant way. Can anyone help? Maybe the following makes it more clear: I like to group the array into 'a' and 'b'-items first like so: a

pandas hwo to groupby create other columns by counting values of existing columns

浪尽此生 提交于 2019-12-24 11:10:12
问题 I got to know how to do this in R( How to make new columns by counting up an existing column), but I'd like also to know how it works in python as well. 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: Use melt with GroupBy.size and unstack: df = (df.melt('userID') .groupby(['userID','variable','value']) .size() .unstack

Attribute error using Jinja2 grouby filter

╄→гoц情女王★ 提交于 2019-12-24 11:09:43
问题 Trying to get the groupby filter to work I'm getting an Atribute error. My groupby code looks like: {% for year, year_purchases in purchases|groupby('PurchaseDate.year')|reverse %} <h2 class="year">{{ year }}</h2> {% for ... %} {% endfor %} {% endfor %} Where purchases is a list of PurchaseEntity: class PurchaseEntity: def __init__(self): self.PurchaseDate = '' self.Orders = [] def load_from_query(self,result): self.PurchaseDate = result.PurchaseDate I'm getting the following error:

nhibernate group by join query

强颜欢笑 提交于 2019-12-24 10:59:01
问题 I have the following entities: public class Shift { public virtual int ShiftId { get; set; } public virtual string ShiftDesc { get; set; } public virtual IList<ShiftHistory> ShiftHistory { get; set; } } public class ShiftHistory { public virtual System.DateTime ShiftStartLocal { get; set; } public virtual System.DateTime ShiftEndLocal { get; set; } public virtual Zone Zone { get; set; } public virtual Shift Shift { get; set; } public virtual int RowId { get; set; } } public class Zone {

Add comma-separated value of grouped rows to existing query

大兔子大兔子 提交于 2019-12-24 10:54:02
问题 I've got a view for reports, that looks something like this: SELECT a.id, a.value1, a.value2, b.value1, /* (+50 more such columns)*/ FROM a JOIN b ON (b.id = a.b_id) JOIN c ON (c.id = b.c_id) LEFT JOIN d ON (d.id = b.d_id) LEFT JOIN e ON (e.id = d.e_id) /* (+10 more inner/left joins) */ It joins quite a few tables and returns lots of columns, but indexes are in place and performance is fine. Now I want to add another column to the result, showing comma-separated values ordered by value from