mirror of
https://github.com/Rain-kl/OpenFlare.git
synced 2026-09-30 14:26:36 +08:00
压缩历史至 95081aff
This commit is contained in:
@@ -0,0 +1,45 @@
|
||||
CREATE DATABASE IF NOT EXISTS linux_do_credit;
|
||||
|
||||
USE linux_do_credit;
|
||||
|
||||
CREATE TABLE IF NOT EXISTS orders
|
||||
(
|
||||
id UInt64,
|
||||
order_name String,
|
||||
merchant_order_no String,
|
||||
client_id String,
|
||||
payer_user_id UInt64,
|
||||
payee_user_id UInt64,
|
||||
amount Decimal(20, 2),
|
||||
status LowCardinality(String),
|
||||
type LowCardinality(String),
|
||||
remark String,
|
||||
payment_type LowCardinality(String),
|
||||
trade_time DateTime,
|
||||
expires_at DateTime,
|
||||
created_at DateTime,
|
||||
updated_at DateTime
|
||||
)
|
||||
ENGINE = ReplacingMergeTree(updated_at)
|
||||
PARTITION BY toYYYYMM(created_at)
|
||||
ORDER BY (created_at, id)
|
||||
SETTINGS index_granularity = 8192;
|
||||
|
||||
-- ============================================================
|
||||
-- 常用查询示例
|
||||
-- ============================================================
|
||||
|
||||
-- 查询单个订单(加 FINAL 获取最新版本)
|
||||
-- SELECT * FROM orders FINAL WHERE id = 1001;
|
||||
|
||||
-- 按用户统计订单
|
||||
-- SELECT payer_user_id, count() AS cnt, sum(amount) AS total
|
||||
-- FROM orders FINAL
|
||||
-- WHERE status = 'success'
|
||||
-- GROUP BY payer_user_id;
|
||||
|
||||
-- 按月统计(利用分区裁剪)
|
||||
-- SELECT toYYYYMM(created_at) AS month, count() AS orders, sum(amount) AS volume
|
||||
-- FROM orders FINAL
|
||||
-- GROUP BY month
|
||||
-- ORDER BY month;
|
||||
Reference in New Issue
Block a user