| email |
+---------------------------------+
| abcd@gmail.com |
| bdef@gmail.com abdfgr@yahoo.com |
+---------------------------------+
我尝试了下面的内容,它正在为第一行工作
substr(email,instr(email,'@',1,1))
但是对于同一个小区的第二行,我们有2个域ID。现在,如何检索输出如下
gmail.com
gmail.com
yahoo.com
答案 0 :(得分:2)
例如:
public ActionResult DisplaySearchResults(int[] SelectedGenres) //selected genres from multiselect list
{
List<Movie> SelectedMovies = new List<Movie>();
SelectedMovies = db.Movies.ToList();
var query = from r in db.Movies.Include("Genres")
select r;
if (SelectedGenres == null || SelectedGenres.Count() == 0)
{
ViewBag.SelectedGenre = "No genre was selected";
}
else
{
foreach (int GenreID in SelectedGenres)
{
//need to query where there's at least one genre, not all
//EX.Western and Horror selected should return movies that have either western or horror as a genre, not both.
query = query.Where(r => r.Genres.Any(x => x.GenreID == GenreID));
}
}
SelectedMovies = query.ToList();
return View("Index", SelectedMovies);
}
答案 1 :(得分:0)
您可以使用REGEXP_SUBSTR,例如:
SELECT REGEXP_SUBSTR ('jlora@outlook.com', '(\@).*') from DUAL
结果:@ outlook.com
答案 2 :(得分:0)
您可以尝试以下内容。我假设你的桌子上还有一个或多个主键列也有电子邮件列:
email
See SQL Fiddle here(忽略架构!)。
现在上面的查询将获得所有结果,包括重复项,因此,如果you@yahoo.com you@gmail.com you@gmail.com
列中的值如下所示:gmail.com
那么SELECT
将为该主键返回两次值。只需将SELECT DISTINCT
替换为{{1}}即可解决该问题(如果您想绕过它)。