SQL Server中如何使用GROUP BY进行数据分组查询?
- 内容介绍
- 文章标签
- 相关推荐
本文共计169个文字,预计阅读时间需要1分钟。
sqlSELECT g.GameItem, g.UserId, b.vipLevel, (SELECT orderId FROM G_Game_Order a WHERE g.userId=a.userId AND SettleTime='2023-09-25 00:00:00' AND SettleTime='2023-09-25 23:59:59' AND XmState=0 AND status=1 FOR XML PATH(''))AS orderIdListFROM G_Game g, B_User b
select g.GameItem,g.UserId,b.vipLevel,
CAST((
SELECT a.orderId+',' FROM G_Game_Order a
WHERE g.userId=a.userId and SettleTime>='2023-09-25 00:00:00' and SettleTime<='2023-09-25 23:59:59' and XmState=0 and status=1
FOR XML PATH('')) as varchar(max)) as maskdetail
from G_Game_Order as g ,C_User_Register as b
where g.UserId= b.UserId and SettleTime>='2023-09-25 00:00:00' and SettleTime<='2023-09-25 23:59:59' and XmState=0 and status=1
group by g.GameItem,g.UserId,b.vipLevel
本文共计169个文字,预计阅读时间需要1分钟。
sqlSELECT g.GameItem, g.UserId, b.vipLevel, (SELECT orderId FROM G_Game_Order a WHERE g.userId=a.userId AND SettleTime='2023-09-25 00:00:00' AND SettleTime='2023-09-25 23:59:59' AND XmState=0 AND status=1 FOR XML PATH(''))AS orderIdListFROM G_Game g, B_User b
select g.GameItem,g.UserId,b.vipLevel,
CAST((
SELECT a.orderId+',' FROM G_Game_Order a
WHERE g.userId=a.userId and SettleTime>='2023-09-25 00:00:00' and SettleTime<='2023-09-25 23:59:59' and XmState=0 and status=1
FOR XML PATH('')) as varchar(max)) as maskdetail
from G_Game_Order as g ,C_User_Register as b
where g.UserId= b.UserId and SettleTime>='2023-09-25 00:00:00' and SettleTime<='2023-09-25 23:59:59' and XmState=0 and status=1
group by g.GameItem,g.UserId,b.vipLevel

