mysql限制无法针对1个id处理多条记录

mysql限制无法针对1个id处理多条记录,mysql,database,stored-procedures,limit,Mysql,Database,Stored Procedures,Limit,Mysql过程针对1个id提供了三条记录。我试图针对1个id只获取1条记录。在哪里设置限制,以针对1个id只访问1条记录 创建定义者=xxxx@xxxx.%过程xxxx( 如果需要行,可以将限制1添加到YRU查询中 SELECT `zp`.`PlaceId`, `zp`.`PlaceName`, `zp`.`PlaceCategoryCode`, `zp`.`Description`, `zp`.`CompanyId_FK`, `z

Mysql过程针对1个id提供了三条记录。我试图针对1个id只获取1条记录。在哪里设置限制,以针对1个id只访问1条记录

创建定义者=
xxxx
@
xxxx.%
过程
xxxx
(


如果需要行,可以将限制1添加到YRU查询中

 SELECT 
     `zp`.`PlaceId`,
     `zp`.`PlaceName`,
     `zp`.`PlaceCategoryCode`,
     `zp`.`Description`,
     `zp`.`CompanyId_FK`,
     `zp`.`OwnerCompanyId_FK`,
     `zp`.`IsDeleted`,
     `zp`.`IsArchived`,
     `zp`.`CreatedDate`,
     `zp`.`ModifiedDate`,
     `zp`.`CreatedBy_FK`,
     `zp`.`ModifiedBy_FK`,
     (SELECT COUNT(`ApplianceId`) FROM `ZThinQ_Appliance` WHERE `ApplianceActionCode` = 1 AND `PlaceId_FK` = `PlaceId`)  AS activeDevices ,
     (SELECT COUNT(`ApplianceId`) FROM `ZThinQ_Appliance` where  `PlaceId_FK` = `PlaceId` ) AS totalDevices

    FROM `ZThinQ_Place` AS `zp` 
    JOIN `ZThinQ_Appliance` as `za`

    #ON `ZThinQ_Appliance`
    #ON `PlaceId` = `PlaceId_FK` 

    Where `zp`.`CompanyId_FK`=pCompanyId
    LIMIT 1 

我有一个id的多个记录。所以我在我的过程中使用select distinct。就是这样

SELECT distinct
 `zp`.`PlaceId`,
 `zp`.`PlaceName`,
 `zp`.`PlaceCategoryCode`,
 `zp`.`Description`,
 `zp`.`CompanyId_FK`,
 `zp`.`OwnerCompanyId_FK`,
 `zp`.`IsDeleted`,
 `zp`.`IsArchived`,
 `zp`.`CreatedDate`,
 `zp`.`ModifiedDate`,
 `zp`.`CreatedBy_FK`,
 `zp`.`ModifiedBy_FK`,
 (SELECT COUNT(`ApplianceId`) FROM `ZThinQ_Appliance` WHERE `ApplianceActionCode` = 1 AND `PlaceId_FK` = `PlaceId`)  AS activeDevices ,
 (SELECT COUNT(`ApplianceId`) FROM `ZThinQ_Appliance` where  `PlaceId_FK` = `PlaceId` ) AS totalDevices

FROM `ZThinQ_Place` AS `zp` 
JOIN `ZThinQ_Appliance` as `za`

#ON `ZThinQ_Appliance`
#ON `PlaceId` = `PlaceId_FK` 

Where `zp`.`CompanyId_FK`=pCompanyId
LIMIT 1 

您的回答是对的,但我需要
PlaceId
的一条记录,它的响应为3@scaisEdge@LODE我不明白..请更好地解释..尝试更新您的问题添加适当的数据样本、您的实际结果和预期结果您可以通过添加表定义、样本日期和预期结果作为tex来改进此问题t回答问题。@scaisEdge请审阅并接受可能对其他人有帮助的内容
SELECT distinct
 `zp`.`PlaceId`,
 `zp`.`PlaceName`,
 `zp`.`PlaceCategoryCode`,
 `zp`.`Description`,
 `zp`.`CompanyId_FK`,
 `zp`.`OwnerCompanyId_FK`,
 `zp`.`IsDeleted`,
 `zp`.`IsArchived`,
 `zp`.`CreatedDate`,
 `zp`.`ModifiedDate`,
 `zp`.`CreatedBy_FK`,
 `zp`.`ModifiedBy_FK`,
 (SELECT COUNT(`ApplianceId`) FROM `ZThinQ_Appliance` WHERE `ApplianceActionCode` = 1 AND `PlaceId_FK` = `PlaceId`)  AS activeDevices ,
 (SELECT COUNT(`ApplianceId`) FROM `ZThinQ_Appliance` where  `PlaceId_FK` = `PlaceId` ) AS totalDevices

FROM `ZThinQ_Place` AS `zp` 
JOIN `ZThinQ_Appliance` as `za`

#ON `ZThinQ_Appliance`
#ON `PlaceId` = `PlaceId_FK` 

Where `zp`.`CompanyId_FK`=pCompanyId
LIMIT 1