本节介绍如何通过ClickHouse进行查询操作。

操作步骤

  1. 连接集群。请参考连接集群
  2. 导入数据。请参考导入数据一节进行数据导入操作。
  3. 数据查询。执行如下SQL语句:
    $ ./clickhouse-client --multiline --host=<host> --port=<port> --user=<user> --password=<password> 
    
    :) SELECT
        OriginCityName,
        DestCityName,
        count(*) AS flights,
        bar(flights, 0, 20000, 40)
    FROM ontime_distributed 
    WHERE Year = 1988
    GROUP BY OriginCityName, DestCityName 
    ORDER BY flights DESC 
    LIMIT 20;
    
    :) SELECT
        OriginCityName < DestCityName ? OriginCityName : DestCityName AS a,
        OriginCityName < DestCityName ? DestCityName : OriginCityName AS b,
        count(*) AS flights,
        bar(flights, 0, 40000, 40)
    FROM ontime_distributed 
    WHERE Year = 1988 
    GROUP BY a, b 
    ORDER BY flights DESC 
    LIMIT 20;
    
    :) SELECT OriginCityName, count(*) AS flights
    FROM ontime_distributed 
    GROUP BY OriginCityName 
    ORDER BY flights DESC 
    LIMIT 20;