vb.net - How to achieve this model -


i have table this

i have table this

i trying achieve table this: enter image description here

this query.

select name,token , sum(qty) [qty],sum(amount)from #temp   group token,name 

tried this..

 select *    (select  name,                qty,amt,                token                  #temp1        ) d        pivot(sum(amt)             token in ([10],[20],[100],[40],[5])) p  

it not working though. appreciated.

i think can achieve following statement:

select      [name],     sum((case when [token] = 10 [qty] else 0 end)) token_10_qty,     sum((case when [token] = 10 [amt] else 0 end)) token_10_amt,     sum((case when [token] = 50 [qty] else 0 end)) token_50_qty,     sum((case when [token] = 50 [amt] else 0 end)) token_50_amt,     sum((case when [token] = 100 [qty] else 0 end)) token_100_qty,     sum((case when [token] = 100 [amt] else 0 end)) token_100_amt      #temp1 group     [name] 

assuming columns qty , amt not null. hope way.


Comments

Popular posts from this blog

java - Plugin org.apache.maven.plugins:maven-install-plugin:2.4 or one of its dependencies could not be resolved -

Round ImageView Android -

How can I utilize Yahoo Weather API in android -