Last updated
Was this helpful?
Last updated
Was this helpful?
Using the COUNT
aggregate function you can count the records in a table. Run the following SQL to see how many records we have on the customers_partitioned
:
Using the SUM
function you can sum records in a table.
To group data use the GROUP BY
clause:
Let’s see how many customers there are from each country. Here is the code which computes that:
SELECT
COUNT(*) AS count
, country
FROM customer
GROUP BY country
/* Output
2 Canada
3 UK
2 Australia
1 India
1 Brazil
5 USA
1 Germany
*/
This page describes how to aggregate Kafka data in Lenses SQL Studio.
SELECT
COUNT(*) AS total
FROM customers_partitioned
SELECT
SUM(quantity * price) AS amount
FROM groceries
CREATE TABLE customer (
firstName STRING
, lastName STRING
, city STRING
, country STRING
, phone STRING)
FORMAT(string, avro)
properties(compacted=true);
INSERT INTO customer (
_key
,firstName
, lastName
, city
, country
, phone)
VALUES
('1','Craig', 'Smith', 'New York', 'USA', '1-01-993 2800'),
('2','William', 'Maugham','Toronto','Canada','+1-613-555-0110'),
('3','William', 'Anthony','Leeds','UK', '+44 1632 960427'),
('4','S.B.','Swaminathan','Bangalore','India','+91 7513200000'),
('5','Thomas','Morgan','Arnsberg','Germany','+49-89-636-48018'),
('6','Thomas', 'Merton','New York','USA', '+1-617-555-0147'),
('7','Piers','Gibson','London','UK', '+44 1632 960269'),
('8','Nikolai','Dewey','Atlanta','USA','+1-404-555-0178'),
('9','Marquis', 'de Ellis','Rio De Janeiro','Brazil','+55 21 5555 5555'),
('10','Joseph', 'Milton','Houston','USA','+1-202-555-0153'),
('11','John','Betjeman Hunter','Sydney','Australia','+61 1900 654 321'),
('12','Evan', 'Hayek','Vancouver','Canada','+1-613-555-0130'),
('13','E.','Howard','Adelaide','Australia','+61 491 570 157'),
('14','C. J.', 'Wilde','London','UK','+44 1632 960111'),
('15','Butler', 'Andre','Florida','USA','+1-202-555-0107');