The method of sql multi-table row-to-column and cascading row-to-column
This article mainly explains "the method of sql multi-table row transfer and cascade row transfer". Interested friends may wish to have a look at it. The method introduced in this paper is simple, fast and practical. Now let the editor to take you to learn the "sql multi-table row transfer and cascading row transfer method"!
There are two tables A, A, B, A, B, A, A, B, B, A, B, A, B, B, A, B, Table B is required to display a list of clicks on all items of the day with the following code: declare @ sql varchar (2000) set @ sql='select CONVERT (varchar, a. [Time], 23) as time, total count (b.title) as' select @ sql= @ sql+' Sum (case b.title when''+ Title+''' then 1 else 0 end) as'+ ['+ Title+'] 'from (select distinct title from B) as B set @ sql=@sql+' from An as a left join B as b on a.AId=B.Aid group by CONVERT (varchar, a. [Time], 23) order by CONVERT (varchar (100), a. [Time], 23) desc' exec (@ sql)
Display result time Total Commodity 1 Commodity 2 Commodity 32013-11-1151042013-11-10132111
At this point, I believe that everyone on the "sql multi-table row transfer and cascade row transfer method" have a deeper understanding, might as well to the actual operation of it! Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!