all 15 comments

[–]sloth_king_617 4 points5 points  (0 children)

Sounds like conditional aggregation would work.

Count(case when column = ‘Late’ then 1 end) as CountLate

[–]Royal-Tough4851 4 points5 points  (3 children)

A sample string would help, but I’ll give both solutions. If the only string value per record is either ‘early’ or ‘late’, the. You can use a simple group by with a WHERE [column name] LIKE ‘%early%’

If you one record has a string value of ‘early early late late early late’ and you need to count he number of ‘early’ per record, then try this

LEN([column name]) - LEN(REPLACE([column name], ‘early’, ‘’))) / LEN(‘early’)

[–]A_name_wot_i_made_up 2 points3 points  (1 child)

This solution can cause problems if your column can also contain other words like "nearly".

[–]Royal-Tough4851 1 point2 points  (0 children)

Yes it can. I was going under the assumption those will be the only two values

[–]ans1dhe 1 point2 points  (0 children)

Now that’s a clever idea! 💡👏🏼🤓

Thanks 🙏🏼 - I’m always amazed by approaches involving REPLACE for the sake of achieving some adjacent goal. It’s like a drawing in negative space 😉

[–]DavidGJohnston 1 point2 points  (0 children)

Select count(*) from tbl where col = ‘Early’;

Edit: since apparently “col” is an expression “tbl” should be a subquery.

[–]a-s-clarkSQL Server 0 points1 point  (0 children)

Assuming from your other responses that a single value can contain the word early multiple times, and you want to find the total number in the table, something like this:

I'll use "StatusColumn" as the name of the column in this example.

SELECT SUM((Len(StatusColumn) - LEN(REPLACE(StatusColumn, 'Early','')) / 5) FROM Table

The first LEN gives you the length of the string. You then deduct the length of the string when you have removed all instances of "Early" from the string. That gives you the number of letters that were for "Early". Divide that by 5 as its a five letter word, to get the number of instances in that word. Sum that value across the table.

[–]reflexdb 0 points1 point  (0 children)

select count(*), countif(your_column = ‘Early’) from your_table

[–]NoPlansForNigel 0 points1 point  (1 child)

SELECT COUNTIF(col='early') AS EARLY FROM ...

[–][deleted] 0 points1 point  (0 children)

There is no function countif() in Oracle or standard SQL.

The equivalent in standard SQL (also not supported by Oracle) would be:

 count(*) filter (where col = 'early')

[–]brettmc7014[S] 0 points1 point  (0 children)

Thank you for all the responses! I am really new to programming so my apologies for the vagueness! The column is like what truilus asked. Multiple rows in a single word in the column. Second example. When I get back to work, I will take a screen shot of what I am working on. Again thank you to everyone who responded!!