pivot - How to show data as per my requirement in sql server 2005 -


here table structure

create table dailyfinishjobshistory (    rowid   int not null identity (1, 1),     [job type]  varchar(16) not null,     [no of jobs]  int not null default ((0)),     [turnaround time] decimal(10,2) not null default ((0)),     [one day per]  decimal(8,2),   createddate datetime default (getdate()) ) 

this way data stored in table screen shot

enter image description here

now have show data way & order date asc , clause there need specify 2 date.

date   our_no of jobs  our_turnaround_time our_one day per salesnew_ of jobs salesnew_no of jobs salesnew_turnaround_time way need show... 

i guess need use pivot whatever tried did not work. appreciated. thanks

your question , requirements not clear going take guess want following:

select   convert(varchar(10), createddate, 120) date,   sum(case when [job type] = 'our' [no of jobs] else 0 end) ournoofjobs,   sum(case when [job type] = 'our' [turnaround time] else 0 end) ourturnaroundtime,   sum(case when [job type] = 'our' [one day per] else 0 end) ouronedayper,   sum(case when [job type] = 'salesnew' [no of jobs] else 0 end) salesnewnoofjobs,   sum(case when [job type] = 'salesnew' [turnaround time] else 0 end) salesnewturnaroundtime,   sum(case when [job type] = 'salesnew' [one day per] else 0 end) salesnewonedayper dailyfinishjobshistory group convert(varchar(10), createddate, 120); 

see sql fiddle demo.

this uses aggregate function , case expression convert , rows of data columns using sum function aggregate values in columns want.


Comments

Popular posts from this blog

java.util.scanner - How to read and add only numbers to array from a text file -

rewrite - Trouble with Wordpress multiple custom querystrings -

debian - 500 Error upon login into Plesk Admin - auth.php3? -