How to get the total count of records after union of CTE tables in SQL? -
i applying cte on 3 4 tables , combining results using union.i not storing combined result anywhere. facing challenge total number records resulted after union of these 4 tables.
also have select limited number of rows based on flag set if export excel set select 25000 records else select 10000 records.
please me on this.
code sample looks below:
with item_characteristics_cte ( select sequence, item_id item_characteristics_log ), item_required_quantity_log_cte ( select sequence, item_id item_required_quantity_log ) select c1.item_id item_characteristics_cte c1 inner join item_characteristics_cte c2 on c1.sequence = c2.sequence union select c1.item_id item_id item_required_quantity_log_cte c1 inner join item_required_quantity_log_cte c2 on c1.sequence = c2.sequence c2.rn = c1.rn
i not sure flag mean in above question. count, use 1 additional cte this:
;with item_characteristics_cte ( select sequence ,item_id item_characteristics_log ) ,item_required_quantity_log_cte ( seelect sequence ,item_id item_required_quantity_log ) ,item_id_count ( select c1.item_id item_characteristics_cte c1 inner join item_characteristics_cte c2 on c1.sequence = c2.sequence union select c1.item_id item_id item_required_quantity_log_cte c1 inner join item_required_quantity_log_cte c2 on c1.sequence = c2.sequence c2.rn = c1.rn ) select item_id ,count(item_id) item_id_count
Comments
Post a Comment