Quantcast
Channel: Transact-SQL forum
Viewing all articles
Browse latest Browse all 23857

More elegant way of writing this query w/o using CTE and variables?

$
0
0

Each CTE returns two values: I divide one by the other and I get a percentage.

The query works, but I don't think I need a cte or variables for this.

So how can this look more elegant?

Thanks.

;with cte2 as (
	select FIELD1 From TABLE1 where FIELD2 not like 'ABC%' and FIELD1 not in (
	select FIELD1 From TABLE1 where FIELD2 like 'ABC%'
	group by FIELD1 )
	group by FIELD1
) select count(*) from cte2

;with cte as (
	select FIELD1 From TABLE1 group by FIELD1
)
select count(*) from cte



VM


Viewing all articles
Browse latest Browse all 23857

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>