count the number of email inside a column's entity - mysql

I have a table that has a column named 'bio', which is a string of max length 255. Inside this bio I want to search if there's an email contained in it. I want to count how many entries in the table that has an email in the bio column. Is such thing possible to be done via SQL?
To add more clarification, bio is a free form text and I am looking to match the email pattern, and not a specific email.

You can use a query like this:
select count(*)
from mytable
where bio REGEXP '<emailregexp>'
Replace <emailregexp> with the regular expression you're using to match email patterns. There are dozens of answers for that on SO, e.g.
Using a regular expression to validate an email address
However, most of these questions are about validating an email, which assumes that the entire input field is supposed to be a single email. Make sure you remove the ^ and $ anchors for the ends of the input so that yo look for an email anywhere in the field.

Related

MySQL db - Can i use a wildcard inside a field?

I'm not sure if this is possible but I have a small MySql database that is used with a call screener app for my PBX.. I can add single numbers such as (555) 123-4567, however I would like to enter in entire blocks of numbers like (555) 123-???? so that any number calling from the numbers (555) 123-0000 through (555) 123-9999 would be selected in one entry. I know you can use wildcards in queries etc., but can they be used inside row or column fields?
I think that should work, if you reverse the parameters of like. So if you have a table with 'number masks' to match with (assuming some table and column names here), it could look like this:
select * from NumberMasks m where :CallerNumber like m.Mask
For clarity: :CallerNumber is the phone number of the caller. NumberMasks is just an assumed name for the table, where Mask would be the column containing the mask to match with in the form of (555) 123-???? as specified in the question.

How can I group data by matching identical cells in same column then counting instances of a related column?

data output
I am pretty new to Webi and am having an issue creating a variable. I'm trying to check if there is more than 1 email address for each entity legacy account number and if 1 of the contact names contains "Annual Report". So when I flag each entity legacy account number for no email only the ones without a contact name that contains "Annual Report" will be pulled. In the example above only the yellow groups should be called no email. Right now all of them are being pulled into no email. I have tried using if and match as those are what I am most familiar with. Does anyone have any suggestions?
There are number of ways you could do this. I am going to give an example using two variables, but you could easily combine them into one.
Has No Email Var=If(Match(Upper([Contact EmailAddress]); "NOEMAIL*"); 1; 0)
Annual Report Contact Name Var=If(Match(Upper([Contact Name]); "ANNUAL REPORT*"); 1; 0)
Then you would apply a report filter with two components...
Has No Email Var = 1
AND
Annual Report Contact Name Var = 0
Let me explain a few things...
The purpose of the Upper function is the Match function is case sensitive. If you know your email address are always lower case then you could remove that the Upper function and have it match on "noemail*".
It is significant that I only have a asterisk ("*") at the end of the string being sought. That will only find a match where the corresponding column value starts with that string. If you want it to be true whenever the string is found anywhere in the column being searched you would be asterisks on both ends.
You could also put limiting criteria in your query filter. But here is where thing can get confusing. Within the query filter you can choose the Matches pattern operator. However, the wildcard character is different ("%" rather than "*") and you do not put double-quotes around your search text. So you would have some thing like this...
Contact EmailAddress Matches pattern noemail%
AND
Contact Name Different from pattern Annual Report%
I am sure you noticed I didn't convert the search text to uppercase. In the Query Panel Web Intelligence is case-insensitive and would likely follow the case-sensitivity of the database of the source data. All of our databases are case-insensitive so if yours is case-sensitive you may need to play around this this a bit. Or just go with the approach of creating the variables and report filters as I initially laid out.
If you want a wildcard for a single character rather than multiple characters (which is what "*" and "%" will do) you need to use a "?" within your variable definition or a "_" in your query filter.
Hope this helps,
Noel

extract string based on regex for MySQL

I have members emailing in for support instead of using the online support form and they are nice enough to put their Member ID into the Subject line. I would like to extract these Member ID from the Subject line to populate the Member ID field for the support ticket.
At the moment, I am able to use something like below to find the tickets where the Subject line has the string pattern which I am looking for (7 numbers in a row). My difficulty now is how to extract these numbers from the Subject line.
SELECT t.ID, `Subject`
FROM tickets AS t
WHERE `Subject` REGEXP '[1-6][0-9][0-9][0-9][0-9][0-9][0-9]';
I have attempted to use the Strip Non Digit function from here, however, the Subject line may contain other numbers that are not part of the Member ID. How can I extract just the number block that matches that regex?

SQL to omit value if a match

The following field of a table:
AttorneyEmail(varchar(150), null)
Can have more than one email address, but has this email address in all "helpdesk#dns.org".
I have the following within the Where clause to not include in results:
and aa.AttorneyEmail NOT LIKE ('helpdesk%')
But it still does.
Any help would be appreciated.
Regards,
What you're describing doesn't make much sense. If every row contains the helpdesk address within its AttorneyEmail value (as you say) then a WHERE predicate such as you are trying to use (spelled as #AlexK demonstrates) would exclude all rows. (Also, such a DB structure is pretty ugly.)
In that case, if the point is to strip the helpdesk address from the column value in your results, then you need to do so in the selection list, something like
SELECT REPLACE(aa.AttorneyEmail, 'helpdesk#dns.org', '') AS AttorneyEmail,
...
You may need to adjust that to remove excess delimiters; I can't suggest exactly how because I don't know how you are structuring the values.

Microsoft access text filter

I'm currently constructing a database for users. the issue I am stuck with lies with the email field, as users are able to enter their email I then have a column after which is set up to contain the users email provider, for example
The first column will contain
Abc123#abc.com
But as the the second column, in this case I want it to just display the text after the "#" symbol, so it should read
Abc.com
How would I go about setting this filter, or is it even possible? having to enter this manually would make the database inefficient.
You can use split, mid, instr any number of text functions. For example:
Provider = Split(Email & "","#")(1)
Or
Provider = Mid(Email & "", Instr(Email & "","#")+1)
This is assuming you have used a text field for email, if you have used a hyperlink field, and I recommend that you do not, it gets more complicated.