string sql = "select sum(fee) fee,count(*) num,{0} from table t1 {1} where 1=1";
if(true)
{
//首先把where and 条件全部处理后,再执行下面
string str1 = "name"; //group by 字段
string str2 = " left join table2 t2 on (t1.areaId=t2.id)"; //外联的条件
sql+= " group by name order by name desc"; //group by 语句+order by 语句
Response.Write(string.Format(sql, str1, str2));
}
SQL语句,按不同字段进行汇总,string.Format()
最新推荐文章于 2024-02-29 19:11:30 发布