# Write a SOQL query to fetch all Opportunities created in the Last 30 Days whose StageName is not Closed Lost.

**Topic:** Development · **Difficulty:** Easy · **Asked at:** TCS, Wipro, Cognizant · **Tags:** soql, scenario, date-literals

Read it on the site: https://www.forcechallenges.com/interview-questions/write-a-soql-query-to-fetch-all-opportunities-created-in-the-last-30-days-whose-stagename-is-not-closed-lost

## Answer

Combine the `LAST_N_DAYS` date literal with a stage filter.

```soql
SELECT Id, Name, StageName, CreatedDate FROM Opportunity
WHERE CreatedDate = LAST_N_DAYS:30 AND StageName != 'Closed Lost'
```
Date literals avoid hardcoded dates, so the query stays valid every day.

---
Source: ForceChallenges · last updated 2026-10-19
