Add criteria from counting more than 2 field

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • yosiro
    New Member
    • Aug 2012
    • 34

    Add criteria from counting more than 2 field

    Am sory if the title is not matching with this question.

    I have 2 table and 1 query, like this picture below:



    The query said:

    Code:
    SELECT A1, (SELECT COUNT(C1) FROM Table1 WHERE Table2.ID=Table1.C1 OR Table2.ID=Table1.C2) AS Total
    FROM Table2;
    And i want to show the result of query just in year 2016, how to code this query?

    Am sory for my bad english, i hope you understand. Thank you
  • NeoPa
    Recognized Expert Moderator MVP
    • Oct 2006
    • 32634

    #2
    You'd probably want something like :
    Code:
    SELECT [A1]
         , (SELECT Count(*)
            FROM   [Table1]
            WHERE  (Year([Dt])=2016)
              AND  ([Table2].[ID]=[Table1].[C1] OR [Table2].[ID]=[Table1].[C2])) AS [Total]
    FROM   [Table2]

    Comment

    • yosiro
      New Member
      • Aug 2012
      • 34

      #3
      It works, but i want to add 1 column in the query, presented the year after the Total column

      Comment

      • NeoPa
        Recognized Expert Moderator MVP
        • Oct 2006
        • 32634

        #4
        That's a shame. It's a completely different question from the one this thread is about and would require a whole different approach. Really unfortunate that you didn't include the whole question at the start.

        You'll need to post a new question for that one.

        Comment

        Working...