greatest-n-per-group

How to display the total count of the last row by filestatus?

半世苍凉 提交于 2021-01-29 08:13:06
问题 I have to display the total count of the last row by filestatus. tbl_bankdata bank_id | b_orderno| b_bankname| lead_id 1 | 01-01 | 1 | 1 2 | 01-02 | 2 | 1 3 | 02-01 | 3 | 2 4 | 03-01 | 1 | 3 tbl_fileStatus f_id | f_bankid| f_filestatus 1 | 1 | 1 2 | 2 | 1 3 | 2 | 2 4 | 1 | 2 5 | 1 | 3 6 | 3 | 2 7 | 3 | 3 I have two tables tbl_bankdata and tbl_fileStatus . I am sending bank_id in the tbl_fileStatus as a f_bank_id . Now I have to show the last f_bankid count. For example, I have to fetch the

Get apps with the highest review count since a dynamic series of days

三世轮回 提交于 2021-01-28 21:41:12
问题 I have two tables, apps and reviews (simplified for the sake of discussion): apps table id int reviews table id int review_date date app_id int (foreign key that points to apps) 2 questions: 1. How can I write a query / function to answer the following question?: Given a series of dates from the earliest reviews.review_date to the latest reviews.review_date (incrementing by a day), for each date, D , which apps had the most reviews if the app's earliest review was on or later than D ? I think

Oracle SQL: Get top 3 results per “category” [duplicate]

冷暖自知 提交于 2021-01-28 19:31:50
问题 This question already has answers here : Get top results for each group (in Oracle) (5 answers) Limit SQL query to only the top two counts per group [duplicate] (1 answer) First two salaries in each department [duplicate] (3 answers) Closed 2 years ago . I have an Oracle-db-table with multiple sportsteams and sports. Now I need to get the 3 teams (Or less if less than 3 teams) with the lowest id for each sport (based on their id). (In my example Soccer: Barcelona, Real Madrid, PSG / Hockey:

Laravel get last row value form many table in one to Many relationship

£可爱£侵袭症+ 提交于 2021-01-28 08:56:27
问题 I am building an application which has a model with one to many relationship. In the model, the student table has one to many relationship with student address details. I want to retrieve the last row from address details table. I am stuck on how to retrieve that data. I could not work out from similar answer on this website. My current solution is this $students = Student::with('visaDetails', 'addresses', 'instituteDetails', 'subAgents', 'staffDetails', 'commissionDetails', 'comments')-

Laravel get last row value form many table in one to Many relationship

自闭症网瘾萝莉.ら 提交于 2021-01-28 08:43:43
问题 I am building an application which has a model with one to many relationship. In the model, the student table has one to many relationship with student address details. I want to retrieve the last row from address details table. I am stuck on how to retrieve that data. I could not work out from similar answer on this website. My current solution is this $students = Student::with('visaDetails', 'addresses', 'instituteDetails', 'subAgents', 'staffDetails', 'commissionDetails', 'comments')-

SQL Query for DynamicsCRM Most recent activity over all contact per account

喜夏-厌秋 提交于 2021-01-28 05:20:24
问题 I want to list the most recent activity (from FilteredActivityPointer) per account (FilteredAccount). Problem is that activities are not directly linked to account but have contacts in between. So accounts can have multiple contacts. Multiple contacts can have multiple activites. The full entity model Question: How can I retrieve the most recent activity per account? I tried the following (using SQL Server 2016, Transact SQL): SELECT * FROM FilteredContact co cross apply (SELECT TOP 1 * FROM

Using LIMIT within GROUP BY to get N results per group?

假装没事ソ 提交于 2021-01-05 13:20:52
问题 The following query: SELECT year, id, rate FROM h WHERE year BETWEEN 2000 AND 2009 AND id IN (SELECT rid FROM table2) GROUP BY id, year ORDER BY id, rate DESC yields: year id rate 2006 p01 8 2003 p01 7.4 2008 p01 6.8 2001 p01 5.9 2007 p01 5.3 2009 p01 4.4 2002 p01 3.9 2004 p01 3.5 2005 p01 2.1 2000 p01 0.8 2001 p02 12.5 2004 p02 12.4 2002 p02 12.2 2003 p02 10.3 2000 p02 8.7 2006 p02 4.6 2007 p02 3.3 What I'd like is only the top 5 results for each id: 2006 p01 8 2003 p01 7.4 2008 p01 6.8 2001

Using LIMIT within GROUP BY to get N results per group?

痴心易碎 提交于 2021-01-05 13:20:38
问题 The following query: SELECT year, id, rate FROM h WHERE year BETWEEN 2000 AND 2009 AND id IN (SELECT rid FROM table2) GROUP BY id, year ORDER BY id, rate DESC yields: year id rate 2006 p01 8 2003 p01 7.4 2008 p01 6.8 2001 p01 5.9 2007 p01 5.3 2009 p01 4.4 2002 p01 3.9 2004 p01 3.5 2005 p01 2.1 2000 p01 0.8 2001 p02 12.5 2004 p02 12.4 2002 p02 12.2 2003 p02 10.3 2000 p02 8.7 2006 p02 4.6 2007 p02 3.3 What I'd like is only the top 5 results for each id: 2006 p01 8 2003 p01 7.4 2008 p01 6.8 2001

Using LIMIT within GROUP BY to get N results per group?

好久不见. 提交于 2021-01-05 13:19:50
问题 The following query: SELECT year, id, rate FROM h WHERE year BETWEEN 2000 AND 2009 AND id IN (SELECT rid FROM table2) GROUP BY id, year ORDER BY id, rate DESC yields: year id rate 2006 p01 8 2003 p01 7.4 2008 p01 6.8 2001 p01 5.9 2007 p01 5.3 2009 p01 4.4 2002 p01 3.9 2004 p01 3.5 2005 p01 2.1 2000 p01 0.8 2001 p02 12.5 2004 p02 12.4 2002 p02 12.2 2003 p02 10.3 2000 p02 8.7 2006 p02 4.6 2007 p02 3.3 What I'd like is only the top 5 results for each id: 2006 p01 8 2003 p01 7.4 2008 p01 6.8 2001

Using LIMIT within GROUP BY to get N results per group?

試著忘記壹切 提交于 2021-01-05 13:19:30
问题 The following query: SELECT year, id, rate FROM h WHERE year BETWEEN 2000 AND 2009 AND id IN (SELECT rid FROM table2) GROUP BY id, year ORDER BY id, rate DESC yields: year id rate 2006 p01 8 2003 p01 7.4 2008 p01 6.8 2001 p01 5.9 2007 p01 5.3 2009 p01 4.4 2002 p01 3.9 2004 p01 3.5 2005 p01 2.1 2000 p01 0.8 2001 p02 12.5 2004 p02 12.4 2002 p02 12.2 2003 p02 10.3 2000 p02 8.7 2006 p02 4.6 2007 p02 3.3 What I'd like is only the top 5 results for each id: 2006 p01 8 2003 p01 7.4 2008 p01 6.8 2001