Help to build queries for counting specific values

  • Hi All,

    I need some urgent help regarding some T-SQL operation I am currently stuck with

    I have a table which has some columns like skill, parentskill,status,state columns

    Now What i want is whenever some skill is there will be a parentskill for that

    Now I want to get the count of skills coming under individual parent skill

    How to build that query ... I need some suggestion or help urgently

    Thanks in advance

  • We can help you if you provide some table DDL (create table statements) and include sample data (insert statements). Give us also a sample of the output you wish, so we can allready test our solutions before posting it.

    From what I've read in your post you'll need to join the table to itself and grouping the results. The joining will be something like:

    SELECT child.*, par.*

    FROM skill_table child

    LEFT OUTER JOIN skill_table par

    ON child.parentskill = par.skill

    ** Don't mistake the ‘stupidity of the crowd’ for the ‘wisdom of the group’! **
  • I suspect you want to count the children plus the children's children etc? This is a hierarchy and can be solved using a recursive cte. You can either use your favorite search engine to find a solution or you can take a few minutes and read the first article in my signature for best practices when posting questions and we can help you code it.

    _______________________________________________________________

    Need help? Help us help you.

    Read the article at http://www.sqlservercentral.com/articles/Best+Practices/61537/ for best practices on asking questions.

    Need to split a string? Try Jeff Modens splitter http://www.sqlservercentral.com/articles/Tally+Table/72993/.

    Cross Tabs and Pivots, Part 1 – Converting Rows to Columns - http://www.sqlservercentral.com/articles/T-SQL/63681/
    Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs - http://www.sqlservercentral.com/articles/Crosstab/65048/
    Understanding and Using APPLY (Part 1) - http://www.sqlservercentral.com/articles/APPLY/69953/
    Understanding and Using APPLY (Part 2) - http://www.sqlservercentral.com/articles/APPLY/69954/

Viewing 3 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic. Login to reply