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)。完全不需要按其他字段分组!