我有两个表,group
和groupAccess
。一个包含每个"组"的信息,另一个包含访问组的所有时间,包括它的唯一ID和时间戳。
我的目标是在最近访问所有群组时对其进行排序。
我已经到了一半,这个查询允许我以正确的顺序获取所有组,但是我需要删除重复的组。
SELECT a.*
FROM groups a
INNER JOIN groupAccess b ON a.group_id = b.group_access_id
ORDER BY access_time DESC
我已尝试使用GROUP BY
或DISTINCT
,但这会打破群组的(当前)正确顺序。我该如何解决这个问题?
答案 0 :(得分:1)
使用using System;
using System.Web.UI.WebControls;
using System.Net.Mail;
using System.Net;
using System.Linq;
using System.Web;
using System.Web.UI;
namespace WebApplication1
{
public partial class BatchEmail : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
foreach (GridViewRow item in GridView1.Rows)
{
string Email_Address = item.Cells[1].Text.Trim();
MailMessage msg = new MailMessage();
msg.From = new MailAddress("khawarsaleem90@gmail.com");
msg.To.Add(Email_Address);
msg.Subject = TextBox1.Text;
msg.Body = TextBox2.Text;
SmtpClient smt = new SmtpClient("smtp.gmail.com", 587);
smt.Credentials = new System.Net.NetworkCredential("khawarsaleem90@gmail.com", "mypass");
smt.EnableSsl = true;
smt.Send(msg);
}
}
}
}
和max()
查找每个组的最新访问时间,然后将该表与GROUP BY
一起加入。那就是:
group