this is the query how can i write a expression rule for this and the result will be like below
Discussion posts and replies are publicly visible
KM
If your query is a simple select statement, you can directly query from db using QueryEntity or QueryRecordType. Within these you can modify data like applying filers.
In case of joins and unions, I would prefer to go with view in the backend and then query through QueryEntity or QueryRecordType.
Query Recipes - Appian 24.3