SQL Server中如何使用GROUP BY进行数据分组查询?

2026-04-13 19:2810阅读0评论SEO基础
  • 内容介绍
  • 文章标签
  • 相关推荐

本文共计165个文字,预计阅读时间需要1分钟。

SQL Server中如何使用GROUP BY进行数据分组查询?

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 orderIdList

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


SQL Server中如何使用GROUP BY进行数据分组查询?

本文共计165个文字,预计阅读时间需要1分钟。

SQL Server中如何使用GROUP BY进行数据分组查询?

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 orderIdList

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


SQL Server中如何使用GROUP BY进行数据分组查询?