@@ -180,6 +180,40 @@ function createGroupByTests(autoIndex: `off` | `eager`): void {
180180 expect ( customer3 ?. max_amount ) . toBe ( 250 )
181181 } )
182182
183+ test ( `group by customer_id with count aggregation (not null only)` , ( ) => {
184+ const customerSummary = createLiveQueryCollection ( {
185+ startSync : true ,
186+ query : ( q ) =>
187+ q
188+ . from ( { orders : ordersCollection } )
189+ . groupBy ( ( { orders } ) => orders . customer_id )
190+ . select ( ( { orders } ) => ( {
191+ customer_id : orders . customer_id ,
192+ total : count ( orders . id ) ,
193+ onlyNotNull : count ( orders . sales_rep_id ) ,
194+ } ) ) ,
195+ } )
196+
197+ expect ( customerSummary . size ) . toBe ( 3 ) // 3 customers
198+
199+ // Customer 1: orders 1, 2, 7 (total: 3, onlyNotNull: 3)
200+ const customer1 = customerSummary . get ( 1 )
201+ expect ( customer1 ?. total ) . toBe ( 3 )
202+ expect ( customer1 ?. onlyNotNull ) . toBe ( 3 )
203+
204+ // Customer 2: orders 3, 4 (total: 2, onlyNotNull: 2)
205+ const customer2 = customerSummary . get ( 2 )
206+ expect ( customer2 ) . toBeDefined ( )
207+ expect ( customer2 ?. total ) . toBe ( 2 )
208+ expect ( customer2 ?. onlyNotNull ) . toBe ( 2 )
209+
210+ // Customer 3: orders 5, 6 (total: 2, onlyNotNull: 1)
211+ const customer3 = customerSummary . get ( 3 )
212+ expect ( customer3 ) . toBeDefined ( )
213+ expect ( customer3 ?. total ) . toBe ( 2 )
214+ expect ( customer3 ?. onlyNotNull ) . toBe ( 1 )
215+ } )
216+
183217 test ( `group by status` , ( ) => {
184218 const statusSummary = createLiveQueryCollection ( {
185219 startSync : true ,
0 commit comments