You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
[Learn more about `null` handling](./cxl#operators-xpr){.learn-more}
561
+
562
+
560
563
## Group by and having {#group-by}
561
564
562
565
`group by` aggregates rows sharing the same values in the specified elements into summary rows. Aggregate functions like `count`, `sum`, `avg`, `min`, and `max` are then applied per group.
@@ -612,7 +615,11 @@ SELECT from Books {
612
615
613
616
The `order by` clause sorts the result set by one or more [ordering terms](#ordering-term). The default order is ascending (`asc`); use `desc` to reverse it.
614
617
615
-
### Ascending and Descending
618
+
### Ordering Term {#ordering-term}
619
+
620
+

621
+
622
+
616
623
617
624
For example, to list books ordered by price from lowest to highest:
You can specify several ordering terms, separated by commas. The result is sorted by the first term, then by the second for ties, and so on:
634
639
635
640
```cds live
636
641
SELECT from Books { title, author.name as author, price }
637
642
order by author asc, price desc
638
643
```
639
644
645
+
:::info `null` handling
646
+
647
+
By default, the position of `null` values in the sort order is database-specific. Use `nulls first` or `nulls last` to make this explicit:
648
+
649
+
```cds live
650
+
SELECT from Authors { name, dateOfDeath }
651
+
order by dateOfDeath nulls last
652
+
```
653
+
654
+
:::
655
+
656
+
640
657
### Name Resolution — Using Select List Aliases
641
658
642
659
In `order by`, identifiers are resolved against the **select list first**, then against the query source. This means you can order by an alias defined in the projection:
0 commit comments