注意:GROUP_CONCAT是MySQL中特有的函数,使用此函数将影响程序的数据库可移植性!
Mysql查询语句:
1 2 3 4 5 6 7 |
SELECT a.Id,GROUP_CONCAT(b.Name) FROM A a LEFT JOIN B b on a.id=b.UID WHERE a.Id in ('xxx','yyy') GROUP BY a.Id |
SqlSugar的实现方式:
1 2 3 4 5 6 7 8 9 10 11 12 |
var test = db.Queryable<A,B>(a,b)=>new object[] { JoinType.Left, a.Id == b.UId, }.groupby(a=>a.id).select(a,b)=>new Class { xx=a.id xxx=SqlFunc.MappingColumn(default(string), "GROUP_CONCAT(b.Name)")) } |