Write a query to display the number of students having invalid email id.The valid email ids should have “@” anywhere after the first character and should end with “.com”. Give an alias name for the count as ‘student_count’.
Question
Write a query to display the number of students having invalid email id.The valid email ids should have “@” anywhere after the first character and should end with “.com”. Give an alias name for the count as ‘student_count’.
Solution
Assuming you are using a SQL database and the table name is 'students' and the column with the email ids is 'email', the query would look something like this:
SELECT COUNT(*) AS student_count
FROM students
WHERE NOT (email LIKE '_%@%.com');
Here's the step by step explanation:
-
SELECT COUNT(*) AS student_count: This part of the query will count the number of rows returned by the query and give it an alias name 'student_count'. -
FROM students: This part specifies the table we are querying, which is 'students' in this case. -
WHERE NOT (email LIKE '_%@%.com'): This is the condition for the query. It will return the rows where the email does not match the pattern '%@%.com'. The underscore () in the LIKE clause represents exactly one character, the percent (%) represents zero, one, or multiple characters. So this pattern will match any string that has at least one character before the '@', then any characters, then '.com' at the end. The NOT operator negates the condition, so it returns the rows that do not match this pattern, i.e., the rows with invalid email ids.
Similar Questions
Create a class called “Student” with the following details:Name (should contain only alphabets –No numbers and special characters)Register Number in the format (two numbers three characters four numbers)Age (should be greater than 18 and less than 21)Phone number (10 numbers).Write appropriate Exception handling block (separate block for each type of user defined exception) to handle invalid data entry for all data items. If the valid data is entered construct the email id and password of the student and display Email ID format: first name four-digit year @ vitstudent.ac.in and password is “uppercase of first four characters of name + last four numbers of register number+@”Input FormatEnter Name:Enter Reg. Number:Enter Age:Enter Phone Number:Output FormatAditya19BCE1234201234567890
Select the INCORRECT variable names from given below:StudentID#StudentNameenum@AddressD-O-B
You have a database that tracks students by student_id. The entire school is scheduled to go on a field trip to the nation’s capital. In order to attend the field trip, each student must submit a permission slip signed by a parent. You have been storing the scanned permission slips in a table named slips. The field trip is in two weeks. The head of the school wants to send an email to all the students who have not submitted permission slips. You begin typing your query:What should you type in the blank space? (Please type your answer all in upper case. Example: SELECT or UNION ALL)
Write a query to display the number of buildings having an email_address. Give an alias name as 'count_of_buildings_with_email'.Note:1. Display only the count of buildings having an email_address from building table.2. Specify the alias name without any mistake.3. Specify condition and retrieve the correct number of rows.(condition need to be specified on email_address column. If email_address is not null then it must be counted)3. Compare your executed result with the sample output given below.
Write a query to display the number of buildings having an email_address. Give an alias name as 'count_of_buildings_with_email'.Note:1. Display only the count of buildings having an email_address from building table.2. Specify the alias name without any mistake.3. Specify condition and retrieve the correct number of rows.(condition need to be specified on email_address column. If email_address is not null then it must be counted)3. Compare your executed result with the sample output given below.Sample Output:
Upgrade your grade with Knowee
Get personalized homework help. Review tough concepts in more detail, or go deeper into your topic by exploring other relevant questions.