sql - Aggregating quantities across multiple columns without a cursor or temporary table -


if have table 2 columns, , b, , count how many times item shows in both columns, there way without using cursor or temp table?

ex: column   column b bmw           ford jaguar        bmw mercedes      lexus chevrolet     jaguar bmw           ford 

i result be:

bmw        3 jaguar     2 mercedes   1 chevrolet  1 ford       2 lexus      1 

select columna, count(*) times (   select columna atable   union   select columnb atable) joined group columna 

most dbms require alias derived table


Comments

Popular posts from this blog

apache - Add omitted ? to URLs -

redirect - bbPress Forum - rewrite to wwww.mysite prohibits login -

php - How can I stop spam on my custom forum/blog? -