
CREATE DATABASE library;
USE library;

-- 借书趋势
CREATE TABLE  ods_order_count  AS
SELECT
    DATE_FORMAT(time, '%Y-%m') AS month,
    COUNT(*) AS orders
FROM orders
GROUP BY month
ORDER BY month;
-- 用户画像-不同用户借书数量
CREATE table ods_user_type as
SELECT
    u.email AS name,
    COUNT(*) AS value
FROM
    orders o
JOIN
    user u ON o.user_id = u.id
GROUP BY
    u.email
ORDER BY
    value DESC;
