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
Post a Comment