oracle - Comparing outputs from 2 separate sql queries -
i trying write query inventory system. in order have count number of duplicates in 1 table , compare default quantity values taken table.
here 2 queries working currently:
select template_id, count(template_id) howmuch, t.name consumables e, templates t t.consumable_type_id = '2410980' group template_id, t.name having ( count(template_id) > 1 )
the query above takes account of each unique template id , gives me count of how many duplicates present tells me amount of single substance.
select property_descriptors.default_value, templates.name templates, property_descriptors templates.consumable_type_id = '858190' , templates.audit_id = property_descriptors.audit_id , property_descriptors.name = 'reorder point'
this query finds amount of each individual substance have in our system.
my issue dont know of way compare results 2 queries.
ideally, want query give substance have duplicate count lower default value (found using query 2).
any ideas appreciated!
here table schema reference:
consumables
id|template_id|
templates
id|property_descriptor_id|name|audit_id
property_descriptors
id| name|default_value|audit_id
thanks!
select q1.name, q2.default_value - q1.howmuch (select template_id, count(template_id) howmuch, t.name consumables e, templates t t.consumable_type_id = '2410980' group template_id, t.name having ( count(template_id) > 1 )) q1, (select property_descriptors.default_value default_value, templates.name name templates, property_descriptors templates.consumable_type_id = '858190' , templates.audit_id = property_descriptors.audit_id , property_descriptors.name = 'reorder point') q2 q1.name = q2.name
should trick you'll need clean result bit work away negative results or add q2.default_value - q1.howmuch > 0
in outer clause
Comments
Post a Comment