Home > Software design >  How do I use Linq group by like this Code of Oracle?
How do I use Linq group by like this Code of Oracle?

Time:07-27

  select count(*) Amount,
         (trunc(sysdate) - to_date(to_char(a."Admited",'yyyy-mm-dd'),'yyyy-mm-dd')) DiffDay
    from smartipd."Admits" a 
GROUP BY (trunc(sysdate) - to_date(to_char(a."Admited",'yyyy-mm-dd'),'yyyy-mm-dd')) ;

CodePudding user response:

Since I don't have your database available, I have to improvise using the Northwind database. This will give what it appears you are going for in your code: The number of record, by number of days ago.

  from o in Orders
  let dffDate = (DateTime.Now - o.OrderDate.Value).Days
  group o by dffDate into c
  select new {Amount = c.Count(), Days = c.Key}
  • Related