Hi,
What you saw is a very simple implementation use case which will work for one single schema as you have already stated. to make it work with a complex query you have to engage an adobe campaign developer who can build a custom extension to suit this use case.
Creating Custom Extensions for Adobe Campaign then as your AEM developer to consume that extension using a servlet then use that servlet or service in your form.
Regards,
Amit