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 6648845
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T00:42:13+00:00 2026-05-26T00:42:13+00:00

So I have an SQL statement looks like this SELECT T1.NAME, COUNT(T2.VALUE) AS numInstances

  • 0

So I have an SQL statement looks like this

SELECT T1.NAME, COUNT(T2.VALUE) AS numInstances
FROM TABLE2 T2 LEFT OUTER JOIN
     TABLE1 T1 on T2.NAME_ID = T1.NAME_ID
WHERE (T2.DATE BETWEEN to_date('01-Aug-2011', 'dd-mon-yyyy') 
      AND to_date('31-Aug-2011' , 'dd-mon-yyyy')) AND T2.VALUE = 1))
GROUP BY T1.NAME

This statement looks for when names to match in the 2 tables and then find all ‘1’ values (these relate to something like sick day, worked, day off, ect) in the month of august and then count how many of each I have. This SQL statement works great but I’m using MVC .NET in C# and need this to be a LINQ statement that generates a Dictionary.

So i would like the Dictionary to look something like,

NAME   VALUECOUNT
John   8
Joe    1
Eric   0

I’ve tried

Dictionary<string,int> results =
(from t2 in db.table2.Where(t2 => m.Value == 1)
 from t1 in db.table1
 where(t2.DATE >= new DateTime(2011,8,1) && t2.DATE <= new DateTme(2011,8,31)
 orderby t1.NAME
 group new{T2, T1} by new {t2.VALUE, t1.NAME} into g
 select new { 
   new KeyValuePair<string,int>(
      g.Key.NAME,
     (int)g.sum(g => g.Key.Value))
}).AsEnumerable().ToDictionary();

Ideas?

  • 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-05-26T00:42:14+00:00Added an answer on May 26, 2026 at 12:42 am
    using(DbEntities db = new DbEntities())
    {
      var fromDate = new DateTime(2011,8,1);
      var toDate = new DateTime(2011,8,31);
      var dictionary =
                (from t1 in db.TABLE1
                join t2 in db.TABLE2.Where(x => x.VALUE == 1 && x.DATE >= fromDate && x.DATE <= toDate)
                on t1.NAME_ID equals t2.NAME_ID into t2_j
                from t2s in t2_j.DefaultIfEmpty()
                group t2s by t1.NAME into grouped
                select new { Name = grouped.Key, Count = grouped.Sum(x => x.VALUE) }).
                Where(x => x.Count.HasValue).
                ToDictionary(o => o.Name,o => o.Count);
       return dictionary;
    
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a SQL-statement like this: SELECT name FROM users WHERE deleted = 0;
I have a SQL statement that looks like: SELECT [Phone] FROM [Table] WHERE (
i have sql statement like this SELECT DISTINCT results_sp_08.material_number FROM results_sp_08 INNER JOIN courses
I have a SQL statement similar to this: SELECT COUNT(*) AS foo, SUM(foo) AS
I have LINQ statement that looks like this: return ( from c in customers
I have sql statement one; select linkscat.id, linkscat.category from linkscat, contentlinks, links where contentlinks.linksid
I have a SQL Statement where i need to display the value from another
I wrote a T-SQL Statement similar like this (the original one looks different but
I have an annoying SQL statement that seem simple but it looks awfull. I
I have a sql statement that uses Difference => http://msdn.microsoft.com/en-us/library/ms188753.aspx I do this in

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.