comparison tests/agg.ur @ 1187:ad9829c3c12c

COUNT(col)
author Adam Chlipala <adamc@hcoop.net>
date Tue, 16 Mar 2010 15:54:35 -0400
parents 7a7efbb3e354
children 601a77af0477
comparison
equal deleted inserted replaced
1186:a4ac900d3085 1187:ad9829c3c12c
1 table t1 : {A : int, B : string, C : float} 1 table t1 : {A : int, B : string, C : float}
2 table t2 : {A : float, D : int} 2 table t2 : {A : float, D : int, E : option string}
3 3
4 val q1 = (SELECT COUNT( * ) AS X FROM t1) 4 val q1 = (SELECT COUNT( * ) AS X FROM t1)
5 val q2 = (SELECT AVG(t1.A) AS X FROM t1) 5 val q2 = (SELECT AVG(t1.A) AS X FROM t1)
6 val q3 = (SELECT SUM(t1.C) AS X FROM t1) 6 val q3 = (SELECT SUM(t1.C) AS X FROM t1)
7 val q4 = (SELECT MIN(t1.B) AS X, MAX(t1.A) AS Y FROM t1) 7 val q4 = (SELECT MIN(t1.B) AS X, MAX(t1.A) AS Y FROM t1)
8 val q5 = (SELECT SUM(t1.A) AS X FROM t1 GROUP BY t1.B)
9 val q6 = (SELECT COUNT(t2.E) AS N FROM t2 GROUP BY t2.D)
8 10
9 (*val q5 = (SELECT t1.A FROM t1 GROUP BY t1.B)*) 11 fun main () : transaction page =
10 val q5 = (SELECT SUM(t1.A) AS X FROM t1 GROUP BY t1.B) 12 xml <- queryX q6 (fn r => <xml>{[r.N]};</xml>);
11 13 return <xml><body>{xml}</body></xml>
12
13 datatype list a = Nil | Cons of a * list a
14
15 val r1 : transaction (list string) =
16 query q4
17 (fn fs acc => return (Cons (fs.X, acc)))
18 Nil
19
20 val main : unit -> transaction page = fn () =>
21 n <- r1;
22 return <html><body>Nothing to see here!</body></html>