sql server - T sql order by 2 rows according to different dates -


i have table called "customers"

customers table has below columns

companyname varchar(100)     productname varchar(100)     createddate datetime     salesprice money  

i have below data in customer table

companyname (column) - productname (column)  -  createddate (column) -   salesprice (column)                      b                        2015-01-02 00:00:00.000  419,10       c                      d                        2014-04-20 00:00:00.000  30,10                             b                        2014-01-02 00:00:00.000  60,00        c                      d                        2015-04-20 00:00:00.000  540,00      

i want select data below. need order createddate less more like

createddate 2014  createddate 2015  createddate 2014  createddate 2015 

result must below (2014-2015 ordering)

a                      b                  2014-01-02 00:00:00.000  60,00  (this 2014)                      b                  2015-01-02 00:00:00.000  419,10 (this 2015)     c                      d                  2014-04-20 00:00:00.000  30,10  (this 2014)   c                      d                  2015-04-20 00:00:00.000  540,00 (this 2015) 

question:

how can select customer table

first 2014 date 2015 date if exists more 2016 etc.. if companyname same , productname same result in above side ?

what need add order in query.

select * customers order companyname, productname, createddate; 

updated:

select  companyname, productname, createddate, row_number() on (partition year(createddate)                                    order year(createddate)) rownumber    customers order rownumber, year(createddate) 

Comments

Popular posts from this blog

c++ - Difference between pre and post decrement in recursive function argument -

php - Nothing but 'run(); ' when browsing to my local project, how do I fix this? -

php - How can I echo out this array? -