Skip to content

Commit de73141

Browse files
authored
Update README.md
1 parent a7b75cc commit de73141

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

README.md

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,33 @@ var query = QueryAstParser.Parse("...");
159159
query.Where("region", w => w.Exists(BuildRegionScalarQueryByUser(1)));
160160
```
161161

162+
#### 🔍 Expected SQL Output
163+
164+
```sql
165+
WITH user_permissions AS (
166+
SELECT rrp.region
167+
FROM region_reference_permission AS rrp
168+
WHERE rrp.user_id = :user_id
169+
), regional_sales AS (
170+
SELECT orders.region, SUM(orders.amount) AS total_sales
171+
FROM orders
172+
WHERE EXISTS (
173+
SELECT *
174+
FROM (SELECT up.region FROM user_permissions AS up) AS x
175+
WHERE orders.region = x.region
176+
)
177+
GROUP BY orders.region
178+
), top_regions AS (
179+
SELECT rs.region
180+
FROM regional_sales AS rs
181+
WHERE rs.total_sales > (SELECT SUM(x.total_sales) / 10 FROM regional_sales AS x)
182+
)
183+
SELECT orders.region, orders.product, SUM(orders.quantity) AS product_units, SUM(orders.amount) AS product_sales
184+
FROM orders
185+
WHERE orders.region IN (SELECT x.region FROM top_regions AS x)
186+
GROUP BY orders.region, orders.product
187+
```
188+
162189
By dynamically injecting permission-based filtering, we can ensure **secure and flexible query customization**.
163190

164191
## 📌 Conclusion

0 commit comments

Comments
 (0)