0
SELECT     
  ETRN_MFTransactionGroup.FolioNumber,
  ETRN_MFTransactionGroup.PrimaryApplicantContactID,
  ETRN_MFTransaction.PK_TransactionGroupID AS Expr1, 
  ETRN_MFTransaction.PK_SchemeProductID,
  ETRN_MFTransaction.Units,
  PA_E_CUSTOMER.dbo.ECUS_Contact.PK_ContactID, 
  PA_E_CUSTOMER.dbo.ECUS_Contact.UserID,
  PA_E_CUSTOMER.dbo.ECUS_Contact.FName,
  PA_E_CUSTOMER.dbo.ECUS_Contact.MName, 
  PA_E_CUSTOMER.dbo.ECUS_Contact.LName,     
  PA_E_INSTRUMENTS.dbo.EINS_MFSchemeProduct.PK_SchemeProductID AS Expr2, 
  PA_E_INSTRUMENTS.dbo.EINS_MFSchemeProduct.RegistrarCode, 
  ETRN_MFTransactionGroup.PK_TransactionGroupID
FROM
  ETRN_MFTransactionGroup 
INNER JOIN
  ETRN_MFTransaction ON
  ETRN_MFTransactionGroup.PK_TransactionGroupID =  ETRN_MFTransaction.PK_TransactionGroupID
 INNER JOIN
   PA_E_CUSTOMER.dbo.ECUS_Contact ON           
     ETRN_MFTransactionGroup.PrimaryApplicantContactID =                     
      PA_E_CUSTOMER.dbo.ECUS_Contact.PK_ContactID
 INNER JOIN
   PA_E_INSTRUMENTS.dbo.EINS_MFSchemeProduct ON 
     ETRN_MFTransaction.PK_SchemeProductID = 
         PA_E_INSTRUMENTS.dbo.EINS_MFSchemeProduct.PK_SchemeProductID
**GROUP BY
    ETRN_MFTransactionGroup.FolioNumber,**
    ETRN_MFTransactionGroup.PrimaryApplicantContactID,                  
    ETRN_MFTransaction.PK_TransactionGroupID,
    ETRN_MFTransaction.PK_SchemeProductID,
    ETRN_MFTransaction.Units,
    PA_E_CUSTOMER.dbo.ECUS_Contact.PK_ContactID, 
    PA_E_CUSTOMER.dbo.ECUS_Contact.UserID,
    PA_E_CUSTOMER.dbo.ECUS_Contact.FName,
    PA_E_CUSTOMER.dbo.ECUS_Contact.MName, 
    PA_E_CUSTOMER.dbo.ECUS_Contact.LName, 
    PA_E_INSTRUMENTS.dbo.EINS_MFSchemeProduct.PK_SchemeProductID, 
    PA_E_INSTRUMENTS.dbo.EINS_MFSchemeProduct.RegistrarCode,  
    ETRN_MFTransactionGroup.PK_TransactionGroupID

上面的查询工作得很好,但我只需要按 FolioNumber 分组(即 - ETRN_MFTransactionGroup.FolioNumber)。完全不需要按其他字段分组!

4

1 回答 1

0

如果您不想对其他字段进行分组,则需要一些聚合函数来告诉 SQL 如何处理多条记录。MAX 或 MIN 适用于 varchar 字段。SUM, AVERAGE 适用于数字。

于 2013-06-18T12:02:00.960 回答