这个问题烦了我好几天了,今天终于解决了!!
select distinct goods,max(actionid) as actionid,max(userid) as userid,max(username) as username,max(identify) as identify,max(txtAreaCode) as txtAreaCode,max(phone) as phone,max(charname) as charname,max(category) as category,max(sortsid) as sortsid,max(sorts) as sorts,max(fullname) as fullname,max(ip) as ip,max(actiondate) as actiondate,max(deliverymethord) as deliverymethord,max(paymethord) as paymethord,max(state) as state from V_orders where ActionID<>0 and state<>55 Group by goods order by actiondate desc
注意1:如果使用了distinct而没有使用group by子句便会出现如下错误:
错误类型:
Microsoft OLE DB Provider for SQL Server (0x80040E14)
列 'V_orders.goods' 在选择列表中无效,因为该列未包含在聚合函数中,并且没有 GROUP BY 子句。
注意2:没有在group by 里出现的字段全部要有AS别名。