Curt_38 Posted October 21, 2013 Share Posted October 21, 2013 Hi everyone, first time poster. Hope this is ok. I have a table that has 100's of car records. I am creating a form where the dropdown list option selected will sort them into groups of 4 cars based on their year and make. After this the groups will need to have a group id (For example NIS1101). The first 3 letters are the make of the car, first two numbers are the year and the last numbers are the group number. Hope this isn't confusing. How would you sort and allocate a group id to each group? Would it be best to ORDER BY or GROUP BY then make a function to allocate this id? I'm not sure how I would go about this. I appreciate any help I could get. Thanks in advance CREATE TABLE cars ( CarID int (10), Make varchar (255), Model varchar(255), Year varchar(4), EngineSize varchar ( , ); Example Data CarID , Make , Model , Year , EngineSize 16528454, Toyota, Prius, 2007 1.8 45619810, Toyota, AE-86, 2012, 2.0 32541811, Nissan, Skyline, 2008, 3.0 25856181, Mitsubishi, Nimbus, 2000, 2.4 29519815, Toyota, Celica, 2007, 1.8 16916598, Holden, Barina, 2011, 1.6 65619818, Mitsubishi, Evolution, 2008, 2.4 15616518, Holden, Commoodore, 2011, 6.0 Group Data (based on group of 4) GroupID , Make , Model , Year , EngineSize TOY101, Toyota, Prius, 2013, 1.8 TOY101, Toyota, AE-86, 2013, 2.0 TOY101, Toyota, Celica, 2013, 1.8 TOY101, Toyota, Prius, 2012, 1.8 TOY102, Toyota, AE-86, 2012, 2.0 TOY102, Toyota, Celica, 2012, 1.8 NIS201, Nissan, Skyline, 2013, 3.0 NIS201, Nissan, Skyline, 2013, 3.0 NIS201, Nissan, Silvia, 2013, 2.0 NIS201, Nissan, Skyline, 2013, 3.0 NIS202, Nissan, Pulsar, 2013, 2.0 NIS202, Nissan, Skyline, 2012, 3.0 NIS202, Nissan, Pulsar, 2009, 2.0 NIS202, Nissan, Skyline, 2008, 3.0 MIT301, Mitsubishi, Nimbus, 2012, 2.4 MIT301, Mitsubishi, Evolution, 2013, 2.4 MIT301, Mitsubishi, Nimbus, 2012, 2.4 MIT301, Mitsubishi, Evolution, 2008, 2.4 HOL401, Holden, Barina, 2013, 1.6 HOL401, Holden, Commoodore, 2012, 6.0 HOL401, Holden, Barina, 2011, 1.6 HOL401, Holden, Commoodore, 2011, 6.0 HOL402, Holden, Barina, 2010, 1.6 HOL402, Holden, Commoodore, 2007, 6.0 Quote Link to comment Share on other sites More sharing options...
Barand Posted October 21, 2013 Share Posted October 21, 2013 The first 3 letters are the make of the car, first two numbers are the year and the last numbers are the group number. Hope this isn't confusing. It becomes totally confusing once one looks at your sample group ids, which bear little resemblance to to your description of the id structure Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.