table-race-times-summary

cql
INSERT INTO cycling.race_times_summary (
  race_time, race_date
) VALUES (
  '10:01:18', '2017-04-14'
);

INSERT INTO cycling.race_times_summary (race_time, race_date) VALUES ('10:15:20', '2017-04-14');
INSERT INTO cycling.race_times_summary (race_time, race_date) VALUES ('11:15:38', '2017-04-14');
INSERT INTO cycling.race_times_summary (race_time, race_date) VALUES ('12:15:40', '2017-04-14');
INSERT INTO cycling.race_times_summary (race_time, race_date) VALUES ('10:01:18', '2018-07-26');
INSERT INTO cycling.race_times_summary (race_time, race_date) VALUES ('10:15:20', '2018-07-26');
INSERT INTO cycling.race_times_summary (race_time, race_date) VALUES ('11:15:38', '2018-07-26');
INSERT INTO cycling.race_times_summary (race_time, race_date) VALUES ('12:15:40', '2018-07-26');
INSERT INTO cycling.race_times_summary (race_time, race_date) VALUES ('10:01:18', '2019-03-21');
INSERT INTO cycling.race_times_summary (race_time, race_date) VALUES ('10:15:20', '2019-03-21');
INSERT INTO cycling.race_times_summary (race_time, race_date) VALUES ('11:15:38', '2019-03-21');
INSERT INTO cycling.race_times_summary (race_time, race_date) VALUES ('12:15:40', '2019-03-21');
cql
SELECT * FROM cycling.race_times_summary;
cql
SELECT race_date, FLOOR(race_time, 1h), COUNT(*) FROM cycling.race_times_summary
  GROUP BY race_date, FLOOR(race_time, 1h);
cql
SELECT race_date, race_time FROM cycling.race_times_summary
  GROUP BY race_date;
cql
DESCRIBE TABLE cycling.race_times_summary;
cql
DROP TABLE IF EXISTS cycling.race_times_summary;
cql
CREATE TABLE IF NOT EXISTS cycling.race_times_summary (
  race_date date,
  race_time time,
  PRIMARY KEY (race_date, race_time)
);
// end::table-create[]
" >> $results_table
echo "// end::$tag" >> $results_table
echo "Create table race_times_summary"

tag="table-describe-base[]"
echo -e "\n// tag::$tag" >> $results_table
$cqlsh -e "
// tag::table-describe-base[]
DESCRIBE TABLE cycling.race_times_summary;
// end::table-describe-base[]
" >> $results_table
echo "// end::$tag" >> $results_table
echo "Described table."

tag="data-insert[]"
echo -e "\n// tag::$tag" >> $results_table
$cqlsh -e "
// tag::data-insert[]
INSERT INTO cycling.race_times_summary (
  race_time, race_date
) VALUES (
  '10:01:18', '2017-04-14'
);

INSERT INTO cycling.race_times_summary (race_time, race_date) VALUES ('10:15:20', '2017-04-14');
INSERT INTO cycling.race_times_summary (race_time, race_date) VALUES ('11:15:38', '2017-04-14');
INSERT INTO cycling.race_times_summary (race_time, race_date) VALUES ('12:15:40', '2017-04-14');
INSERT INTO cycling.race_times_summary (race_time, race_date) VALUES ('10:01:18', '2018-07-26');
INSERT INTO cycling.race_times_summary (race_time, race_date) VALUES ('10:15:20', '2018-07-26');
INSERT INTO cycling.race_times_summary (race_time, race_date) VALUES ('11:15:38', '2018-07-26');
INSERT INTO cycling.race_times_summary (race_time, race_date) VALUES ('12:15:40', '2018-07-26');
INSERT INTO cycling.race_times_summary (race_time, race_date) VALUES ('10:01:18', '2019-03-21');
INSERT INTO cycling.race_times_summary (race_time, race_date) VALUES ('10:15:20', '2019-03-21');
INSERT INTO cycling.race_times_summary (race_time, race_date) VALUES ('11:15:38', '2019-03-21');
INSERT INTO cycling.race_times_summary (race_time, race_date) VALUES ('12:15:40', '2019-03-21');
// end::data-insert[]
" >> $results_table
echo "// end::$tag" >> $results_table
echo "Insert data"

# Query all
tag="select-all[]"
echo -e "\n// tag::$tag" >> $results_table
$cqlsh -e "
// tag::select-all[]
SELECT * FROM cycling.race_times_summary;
// end::select-all[]
" >> $results_table
echo "// end::$tag" >> $results_table
echo "Select all"

# Query GROUP BY race_date
tag="select-group-by-race-date[]"
echo -e "\n// tag::$tag" >> $results_table
$cqlsh -e "
// tag::select-group-by-race-date[]
SELECT race_date, race_time FROM cycling.race_times_summary
  GROUP BY race_date;
// end::select-group-by-race-date[]
" >> $results_table
echo "// end::$tag" >> $results_table
echo "Select group by race_date"

# Query GROUP BY race_date, floor
tag="select-group-by-floor[]"
echo -e "\n// tag::$tag" >> $results_table
$cqlsh -e "
// tag::select-group-by-floor[]
SELECT race_date, FLOOR(race_time, 1h), COUNT(*) FROM cycling.race_times_summary
  GROUP BY race_date, FLOOR(race_time, 1h);
// end::select-group-by-floor[]
" >> $results_table
echo "// end::$tag" >> $results_table
echo "Select GROUP BY and FLOOR"

Was this helpful?

Give Feedback

How can we improve the documentation?

© 2025 DataStax | Privacy policy | Terms of use | Manage Privacy Choices

Apache, Apache Cassandra, Cassandra, Apache Tomcat, Tomcat, Apache Lucene, Apache Solr, Apache Hadoop, Hadoop, Apache Pulsar, Pulsar, Apache Spark, Spark, Apache TinkerPop, TinkerPop, Apache Kafka and Kafka are either registered trademarks or trademarks of the Apache Software Foundation or its subsidiaries in Canada, the United States and/or other countries. Kubernetes is the registered trademark of the Linux Foundation.

General Inquiries: +1 (650) 389-6000, info@datastax.com