USE ssb1; select * from ( select F, count(*) from (select count(*) F from lineorder where lo_orderdate between 19940101 and 19940110 and lo_quantity <= 20 group by lo_quantity ) a group by F union all select F, count(*) from (select count(*) F from lineorder where lo_orderdate between 19940101 and 19940110 and lo_quantity between 21 and 40 group by lo_quantity ) a group by F) a order by 1, 2; F count(*) 464 1 475 1 475 1 477 1 481 1 483 1 484 1 485 1 488 1 495 1 499 1 500 1 502 1 504 1 507 1 508 2 510 1 512 1 512 1 513 1 514 1 515 2 518 1 519 2 521 1 524 1 527 1 529 1 532 1 534 1 537 1 538 1 541 2 542 1 552 1 566 1