How to design UI for building conditional expressions?
Here is an example of how I solved the problem for a bug database. This was done a decade ago on a linux box, so the L&F is rather motif-ish, but it shows the general concept:
(source: clearlight.com)
It works pretty much as you expect. You can change "ANY of the following" to be "ALL of the following" and the labels on the subsequent lines will change from "or" to "and". The "IS" button can be changed to "IS NOT" as well as "Matches pattern" and a few other choices.
You click on the +/- buttons to add additional criteria. You can create logical groups which allow you to do expressions like "a or (b and c)", yet it still almost reads like a collection of English sentences.
In your case, instead of an "Order by" section you might have a "do these things" section.
This would be cumbersome to use if you have to create very complex queries, but if you're needing a complex query you're probably smart enough not to need a GUI like this. This was designed more for the casual user for simple ad hoc queries.
I would definitely change the way this looks if I had it to do over again, but the basic mechanics work pretty well.