Skip to content

Commit 0804bd7

Browse files
TimelordUKclaude
andcommitted
docs: Add comparison functions and string functions to README
- Added comprehensive documentation for GREATEST/LEAST functions - Documented COALESCE and NULLIF for NULL handling - Added examples showing practical use cases - Updated string functions section to show both method and function styles - Clarified that string functions now work everywhere (SELECT, WHERE, etc.) The documentation now clearly shows the power of these new comparison functions for handling multiple values and NULL cases elegantly. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
1 parent d0844a3 commit 0804bd7

File tree

1 file changed

+43
-3
lines changed

1 file changed

+43
-3
lines changed

README.md

Lines changed: 43 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,37 @@ WHERE SQRT(area) BETWEEN 10 AND 50
151151
**Available Math Functions:**
152152
`ROUND`, `ABS`, `FLOOR`, `CEILING`, `MOD`, `QUOTIENT`, `POWER`, `SQRT`, `EXP`, `LN`, `LOG`, `LOG10`
153153

154+
#### **Comparison & NULL Functions**
155+
```sql
156+
-- Find maximum/minimum across multiple columns
157+
SELECT
158+
id,
159+
GREATEST(salary, bonus, commission) as max_income,
160+
LEAST(jan_sales, feb_sales, mar_sales) as worst_month,
161+
GREATEST(0, balance) as positive_balance -- Clamp negative to zero
162+
FROM employees;
163+
164+
-- Handle NULL values elegantly
165+
SELECT
166+
COALESCE(phone, mobile, email, 'No contact') as primary_contact,
167+
NULLIF(total, 0) as non_zero_total, -- Returns NULL if total is 0
168+
COALESCE(discount, 0) * price as discounted_price
169+
FROM orders;
170+
171+
-- Mixed type comparisons (int/float coercion)
172+
SELECT
173+
GREATEST(10, 15.5, 8) as max_val, -- Returns 15.5
174+
LEAST('apple', 'banana', 'cherry'), -- Returns 'apple'
175+
GREATEST(date1, date2, date3) as latest_date
176+
FROM data;
177+
```
178+
179+
**Comparison Functions:**
180+
- `GREATEST(val1, val2, ...)` - Returns maximum value from list
181+
- `LEAST(val1, val2, ...)` - Returns minimum value from list
182+
- `COALESCE(val1, val2, ...)` - Returns first non-NULL value
183+
- `NULLIF(val1, val2)` - Returns NULL if values are equal, else returns val1
184+
154185
#### **🧮 Scientific Calculator Mode with DUAL Table**
155186
```sql
156187
-- Use DUAL table for calculations (Oracle-compatible)
@@ -200,15 +231,24 @@ WHERE name.Contains('manager')
200231
AND department.Trim() != ''
201232
```
202233

203-
**LINQ-Style String Methods:**
234+
**String Functions & Methods:**
235+
236+
*Method Style (in WHERE clauses):*
204237
- `column.Contains('text')` - Case-insensitive substring search
205238
- `column.StartsWith('prefix')` - Case-insensitive prefix check
206239
- `column.EndsWith('suffix')` - Case-insensitive suffix check
207240
- `column.Length()` - Character count
208241
- `column.IndexOf('substring')` - Find position (0-based, -1 if not found)
209242
- `column.Trim()` - Remove leading/trailing spaces
210-
- `column.TrimStart()` - Remove leading spaces only
211-
- `column.TrimEnd()` - Remove trailing spaces only
243+
244+
*Function Style (anywhere):*
245+
- `TOUPPER(text)`, `TOLOWER(text)` - Case conversion
246+
- `TRIM(text)` - Remove whitespace
247+
- `LENGTH(text)` - String length
248+
- `CONTAINS(text, pattern)` - Check substring
249+
- `STARTSWITH(text, prefix)`, `ENDSWITH(text, suffix)` - Pattern matching
250+
- `SUBSTRING(text, start, length)` - Extract substring
251+
- `REPLACE(text, old, new)` - Replace all occurrences
212252

213253
### 🎯 **Advanced Query Capabilities**
214254

0 commit comments

Comments
 (0)