Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8343089
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T05:57:20+00:00 2026-06-09T05:57:20+00:00

I have an SQL code like; Select GroupName, sum(LineAmount) as Total, WeekNumber, ROW_NUMBER() over

  • 0

I have an SQL code like;

Select GroupName, sum(LineAmount) as Total, WeekNumber,
    ROW_NUMBER() over (partition by WeekNumber order by sum(LineAmount) desc) as RowNum
from
    Invoices
where
    month(InvoiceDate)=month(getdate())
group by
    GroupName,WeekNumber

I would like to convert this to LINQ, but no luck. I am using LINQ to Object. Any help would be appreciated.
TIA

EDIT : Here is some sample data, and the expected result.

public class Invoice
{
    public string GroupName { get; set; }
    public int LineAmount { get; set; }
    public int WeekNum { get; set; }
}

   List<Invoice> theData = new List<Invoice>();
    theData.Add(new Invoice { GroupName = "A", LineAmount = 1, WeekNum = 1});
    theData.Add(new Invoice { GroupName = "A", LineAmount = 2, WeekNum = 1 });
    theData.Add(new Invoice { GroupName = "A", LineAmount = 3, WeekNum = 1 });
    theData.Add(new Invoice { GroupName = "A", LineAmount = 2, WeekNum = 2 });
    theData.Add(new Invoice { GroupName = "A", LineAmount = 3, WeekNum = 2 });
    theData.Add(new Invoice { GroupName = "A", LineAmount = 4, WeekNum = 2 });
    theData.Add(new Invoice { GroupName = "B", LineAmount = 4, WeekNum = 1 });
    theData.Add(new Invoice { GroupName = "B", LineAmount = 3, WeekNum = 1 });
    theData.Add(new Invoice { GroupName = "B", LineAmount = 7, WeekNum = 2 });
    theData.Add(new Invoice { GroupName = "B", LineAmount = 6, WeekNum = 2 });
    theData.Add(new Invoice { GroupName = "B", LineAmount = 5, WeekNum = 2 });

enter image description here

I have removed “where” from my first query as its not a problem at the moment.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T05:57:22+00:00Added an answer on June 9, 2026 at 5:57 am
    theData
    .GroupBy(g => new {g.GroupName, g.WeekNum}, (key, gg) => new {key.GroupName, key.WeekNum, Total = gg.Sum(g => g.LineAmount)})
    .GroupBy(g => g.WeekNum, (weekNum, gg) => gg.OrderByDescending(g => g.Total).Select((g,i) => new {g.GroupName, g.Total, g.WeekNum, RowNum = i}))
    .SelectMany(g => g)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hi I have sql code like that: SELECT vote_id, (SELECT type FROM vote_types WHERE
I have a SQL query that is something like SELECT SUM(price) FROM budget GROUP
IF I have a code like $vals = 50,60,40; IN SQL SELECT * FROM
I have a section of T-SQL code that looks something like this: select @automation_rate
Following Uncle Bob's avice in Clean Code , I'd like to have no SQL
I have this SQL code here.. SELECT cl.clientid, cl.clientname, cl.billingdate, cp.startdate, cp.expiration, (SELECT COUNT(*)
I have a SQL Server View: SELECT SOPOrderReturn.DocumentNo, StockItem.Code, SLCustomerAccount.CustomerAccountNumber, SOPOrderReturn.CustomerID, SOPDocDelAddress.PostalName, SOPDocDelAddress.AddressLine1, SOPDocDelAddress.AddressLine2,
I have a sql good working like this. SELECT B.HESAP_NO, A.TEKLIF_NO1 + '/' +
I have a SQL query like this: SELECT E.HESAP, B.TEKLIF_NO1 + '/' + B.TEKLIF_NO2
I have a query whose code looks like this: SELECT DocumentID, ComplexSubquery1 ... ComplexSubquery5

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.