其中MyCategoryId是uniqueidentifier类型的字段 我必须按照这个来取 请问各位大虾 我该怎么分组去查询呢
5 个解决方案
#1
if object_id('T_ExhProducts') is not null drop table T_ExhProducts
go
create table T_ExhProducts (EntId int,MyCategoryId uniqueidentifier,pid int)
insert T_ExhProducts
select 1, newid(), 1 union all
select 3, newid(), 2 union all
select 2, newid(), 1 union all
select 1, newid(), 1 union all
select 1, newid(), 2 union all
select 3, newid(), 2
go
select max(convert(char(36),MyCategoryId)) from T_ExhProducts group by EntId
/*
------------------------------------
CCA63677-27D9-413E-A6F4-47C0FCFC2F33
81E270E8-D1AF-4387-8251-E772241531B3
A985FD52-E10B-4715-B4FC-A5A4E6E73E98
(所影响的行数为 3 行)
*/
#2
select *
from T_ExhProducts a
where not exists(select 1 from T_ExhProducts where entid = a.entid and MyCategoryId> a.MyCategoryId)
EntId MyCategoryId pid
----------- ------------------------------------ -----------
2 AF8E918B-383A-48D5-A355-17EE8C295302 1
1 EABDA64C-35C3-45CF-BC07-8B5CA008B1D0 1
3 308F8FC6-B986-447F-8A8E-F6CFD07F510D 2
(所影响的行数为 3 行)
#3
不懂,up
#4
select max(convert(char(36),MyCategoryId)),EntId from T_ExhProducts group by EntId ??
怎么解决或者:
select MyCategoryId, Max(EntId) from T_ExhProducts group by EntId ??
怎么解决或者:
select MyCategoryId, Max(EntId) from T_ExhProducts group by EntId ??
#5
select max(convert(char(36),MyCategoryId)),EntId from T_ExhProducts group by EntId ??
怎么解决或者:
select MyCategoryId, Max(EntId) from T_ExhProducts group by EntId ??
#1
if object_id('T_ExhProducts') is not null drop table T_ExhProducts
go
create table T_ExhProducts (EntId int,MyCategoryId uniqueidentifier,pid int)
insert T_ExhProducts
select 1, newid(), 1 union all
select 3, newid(), 2 union all
select 2, newid(), 1 union all
select 1, newid(), 1 union all
select 1, newid(), 2 union all
select 3, newid(), 2
go
select max(convert(char(36),MyCategoryId)) from T_ExhProducts group by EntId
/*
------------------------------------
CCA63677-27D9-413E-A6F4-47C0FCFC2F33
81E270E8-D1AF-4387-8251-E772241531B3
A985FD52-E10B-4715-B4FC-A5A4E6E73E98
(所影响的行数为 3 行)
*/
#2
select *
from T_ExhProducts a
where not exists(select 1 from T_ExhProducts where entid = a.entid and MyCategoryId> a.MyCategoryId)
EntId MyCategoryId pid
----------- ------------------------------------ -----------
2 AF8E918B-383A-48D5-A355-17EE8C295302 1
1 EABDA64C-35C3-45CF-BC07-8B5CA008B1D0 1
3 308F8FC6-B986-447F-8A8E-F6CFD07F510D 2
(所影响的行数为 3 行)
#3
不懂,up
#4
select max(convert(char(36),MyCategoryId)),EntId from T_ExhProducts group by EntId ??
怎么解决或者:
select MyCategoryId, Max(EntId) from T_ExhProducts group by EntId ??
怎么解决或者:
select MyCategoryId, Max(EntId) from T_ExhProducts group by EntId ??
#5
select max(convert(char(36),MyCategoryId)),EntId from T_ExhProducts group by EntId ??
怎么解决或者:
select MyCategoryId, Max(EntId) from T_ExhProducts group by EntId ??