+ Reply to Thread
Results 1 to 12 of 12

SQL Count and countif in single Query

  1. #1
    Registered User
    Join Date
    05-21-2012
    Location
    India
    MS-Off Ver
    Excel 2010 to 2016
    Posts
    15

    SQL Count and countif in single Query

    HI Team,

    I am just trying to learn the SQL and have one question.
    Please have a look on the attached pic and help me to get the result from the data by using SQL query.

    Query need to count the names and then comments based on condition.

    Ex : in attached pic have two names repeated 5 times so the count of each name is 5 and
    for 1st name have 5 comments as "Yes" so count should be 5, for other name in comment we have "Yes" 4 time so result should be 4 (for comments condition value is "Yes")

    Please note: i am unable to attach the sample file as the "Attachments" option is not working.

    Thanks in advance for all your help and support.

    Access data.png

  2. #2
    Forum Moderator alansidman's Avatar
    Join Date
    02-02-2010
    Location
    Steamboat Springs, CO
    MS-Off Ver
    MS Office 365 Version 2405 Win 11 Home 64 Bit
    Posts
    23,872

    Re: SQL Count and countif in single Query

    The paperclip attachment button does not work. Read the yellow banner at the top of this page for how to attach a file.

    Here is a tutorial on how to do it in SQL


    https://www.w3schools.com/sql/sql_groupby.asp

    or



    https://www.w3schools.com/sql/sql_count_avg_sum.asp
    Last edited by alansidman; 12-31-2020 at 07:05 PM.
    Alan עַם יִשְׂרָאֵל חַי


    Change an Ugly Report with Power Query
    Database Normalization
    Complete Guide to Power Query
    Man's Mind Stretched to New Dimensions Never Returns to Its Original Form

  3. #3
    Registered User
    Join Date
    05-21-2012
    Location
    India
    MS-Off Ver
    Excel 2010 to 2016
    Posts
    15

    Re: SQL Count and countif in single Query

    Hi Alansidman,

    Thank you so much for attending my request.

    As advised, attached the sample file for your reference.

    Kindly have a look and advice how to achieve my goal in Access SQL.

    I tried the links provided in the post but failed to achieve the result.

    Kindly advise and thanks in advance for all your help and support.

    Regards,
    Rahaman.

  4. #4
    Forum Moderator alansidman's Avatar
    Join Date
    02-02-2010
    Location
    Steamboat Springs, CO
    MS-Off Ver
    MS Office 365 Version 2405 Win 11 Home 64 Bit
    Posts
    23,872

    Re: SQL Count and countif in single Query

    Sorry, but no file attached. Try again. Read the instructions carefully. Pictures are meaningless. Cannot manipulate data in a picture. If you are trying to attach an Access file, you must zip it first.

  5. #5
    Registered User
    Join Date
    05-21-2012
    Location
    India
    MS-Off Ver
    Excel 2010 to 2016
    Posts
    15

    Re: SQL Count and countif in single Query

    Hi Alansidman,

    Apologies for the inconvenience caused.

    Here is the attachment.

    Regards,
    Rahaman.
    Attached Files Attached Files

  6. #6
    Forum Moderator alansidman's Avatar
    Join Date
    02-02-2010
    Location
    Steamboat Springs, CO
    MS-Off Ver
    MS Office 365 Version 2405 Win 11 Home 64 Bit
    Posts
    23,872

    Re: SQL Count and countif in single Query

    In your Access Query that you created, click on the Design Icon and select SQL and Access will show you the SQL statement.
    Attached Images Attached Images

  7. #7
    Registered User
    Join Date
    05-21-2012
    Location
    India
    MS-Off Ver
    Excel 2010 to 2016
    Posts
    15

    Re: SQL Count and countif in single Query

    Hi Alansidman,

    I am already aware of what you are advising but i am not able to achieve the result what i am expecting.

    my question is simple
    1. first Just count the names
    2 count the comments where it contains word "Yes"

    Expected result : Names (ABC) count is 5 and comment where word "Yes" contain is also 5
    Names (XYZ) count is 5 and comment where word "Yes" contains count is 4.

    Hope i am clear with my question.

    Kindly advise.

    Thanks in advance for all your help and support.

    Regards,
    Rahaman.

  8. #8
    Forum Moderator alansidman's Avatar
    Join Date
    02-02-2010
    Location
    Steamboat Springs, CO
    MS-Off Ver
    MS Office 365 Version 2405 Win 11 Home 64 Bit
    Posts
    23,872

    Re: SQL Count and countif in single Query

    You are not clear at all. You have the answer in your Access Queries. What else do you want?

  9. #9
    Registered User
    Join Date
    05-21-2012
    Location
    India
    MS-Off Ver
    Excel 2010 to 2016
    Posts
    15

    Re: SQL Count and countif in single Query

    Hi Alansidman,

    Let me try one more time....

    Could you please have a look on excel attachment where i have created 3 sheets.
    1. First sheet refers to raw data
    2. Second and third sheets contains the result using formula.
    ( I just used counta and countif formula to get the output/result.)

    The same thing want to achieve using sql query in access database/table.

    Please note : To avoid confusion i have deleted the existing queries in access file.

    if it is still not clear then kindly close the thread, will come back with better explanation after sometimes.

    Once again thank you so much for all your help and support.

    Have a great day and Happy New year too.

    Regards,
    Rahaman.
    Attached Files Attached Files

  10. #10
    Forum Moderator alansidman's Avatar
    Join Date
    02-02-2010
    Location
    Steamboat Springs, CO
    MS-Off Ver
    MS Office 365 Version 2405 Win 11 Home 64 Bit
    Posts
    23,872

    Re: SQL Count and countif in single Query

    Ah! You wish to use SQL in an Excel File. Not in Access. The confusion here is you have posted in the Access Forum. I will direct you to a tutorial and move this thread to Excel General.

    https://smallbusiness.chron.com/use-...cel-41193.html

  11. #11
    Registered User
    Join Date
    05-21-2012
    Location
    India
    MS-Off Ver
    Excel 2010 to 2016
    Posts
    15

    Re: SQL Count and countif in single Query

    Hi Team,

    Here is the solution offered by www.accessforums.net and its working fine.

    Please Login or Register  to view this content.
    Kindly note: thread was not showing in www.accessforums.net to provide the link and it was pending with the moderator for approval.
    and here is the link
    https://www.accessforums.net/showthread.php?t=82580

    Kindly close the thread.

    Thank you so much for all your help and support.

    Regards,
    Rahaman.

  12. #12
    Registered User
    Join Date
    05-21-2012
    Location
    India
    MS-Off Ver
    Excel 2010 to 2016
    Posts
    15

    Re: SQL Count and countif in single Query

    Hi Alansidman,

    Thank you so much for all your help and support.

    Regards,
    Rahaman.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Countif, other than ... count a column but dont count specific rows
    By fergnation19 in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 06-13-2019, 12:11 AM
  2. [SOLVED] Countif query
    By tjdate in forum Excel Formulas & Functions
    Replies: 7
    Last Post: 12-21-2017, 05:32 AM
  3. [SOLVED] Using COUNTIF to count multiple instances of data in a single cell
    By emsterv in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 06-14-2017, 06:50 PM
  4. [SOLVED] COUNTIF query
    By alexw1 in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 09-06-2013, 06:58 AM
  5. Countif Query & sumif query help
    By masond3 in forum Excel General
    Replies: 4
    Last Post: 11-16-2011, 03:42 AM
  6. sumif query & countif query help
    By masond3 in forum Excel General
    Replies: 1
    Last Post: 11-15-2011, 06:56 PM
  7. Sort query on sum of count + additional count
    By TomBP in forum Access Tables & Databases
    Replies: 6
    Last Post: 11-30-2010, 11:43 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1