Home > database >  MSSQL: in the same SQL GROUP BY ordering a different problem
MSSQL: in the same SQL GROUP BY ordering a different problem

Time:12-12

A GROUP BY sorting the problems today, the database version for MSSQL2014.
1. The following is the original table data of the two:
 SELECT RowId, COP_EXG_NO BEGIN_DATE FROM dbo. CUR_EMS3_ORG_BOM WHERE COP_EXG_NO='A9113414' 


 SELECT RowId, COP_EXG_NO BEGIN_DATE FROM dbo. CUR_EMS3_ORG_BOM WHERE COP_EXG_NO='A9137590' 



2. Use the following SQL to query the table data, (because the statement cause data is wrong, so use this false statements, find out the root cause)
 SELECT EMS_NO COP_EXG_NO, MAX (BEGIN_DATE) BEGIN_DATE FROM dbo. CUR_EMS3_ORG_BOM 
GROUP BY EMS_NO COP_EMS_NO, COP_EXG_NO, BEGIN_DATE


3. Export to Excel in looking for the position of the first material (A9113414), find the row date night before:


4. Check another A9137590, found that has not changed:



Check the related information, is a GROUP BY no sorting, but the same SQL statement (step 2) found out in the result set will also have a different sort?
  • Related