Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>First, your table structure is awful. Storing data in a list like that is going to cause you headaches similar to what you are trying to do right now. </p> <p>The problem with a split function is you have no idea what <code>software development</code> or other multi-word tags are - Is that one word or two?</p> <p>I think the only way you will solve this is by creating a table with your tags or using a derived table similar to the following:</p> <pre><code>;with cte (tag) as ( select 'java' union all select 'c++' union all select 'software development' union all select 'sysadmin' union all select 'ood' union all select 'jd' union all select 'see' union all select 'c#' ) select c.tag, count(j.tags) listings from cte c inner join job j on j.tags like '%'+c.tag+'%' group by c.tag </code></pre> <p>See <a href="http://sqlfiddle.com/#!3/f3efd/3" rel="nofollow">SQL Fiddle with Demo</a>. Using this you can get a result:</p> <pre><code>| TAG | LISTINGS | | java | 9 | | c++ | 10 | | software development | 4 | | sysadmin | 2 | | ood | 6 | | jd | 3 | | see | 2 | | c# | 1 | </code></pre> <p>The issue with the above as was pointed out in the comments is how to decide if you have a tag <code>software</code> and <code>development</code>, those will match with the above query.</p> <p>The best solution that you would have to this problem would be to store the tags in a separate table similar to:</p> <pre><code>create table tags ( tag_id int, tag_name varchar(50) ); </code></pre> <p>Then you could use a JOIN table to connect your jobs to the tag:</p> <pre><code>create table tag_job ( job_id int, tag_id int ); </code></pre> <p>Once you have a set up similar to this then it becomes much easier to query your data:</p> <pre><code>select t.tag_name, count(tj.tag_id) listings from tags t inner join tag_job tj on t.tag_id = tj.tag_id group by t.tag_name </code></pre> <p><a href="http://sqlfiddle.com/#!3/3cfd5/1" rel="nofollow"><kbd>See demo</kbd></a></p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload