SELECT 'user' AS row_type, id::text AS k1, email AS k2
FROM users
WHERE email='15858260500@163.com';

SELECT 'sub' AS row_type,
       us.id::text AS k1,
       'user_id='||us.user_id||' | group_id='||us.group_id||' | status='||us.status||
       ' | starts_at='||coalesce(to_char(us.starts_at,'YYYY-MM-DD HH24:MI:SSOF'),'-')||
       ' | expires_at='||coalesce(to_char(us.expires_at,'YYYY-MM-DD HH24:MI:SSOF'),'-')||
       ' | daily_usage='||us.daily_usage_usd||
       ' | weekly_usage='||us.weekly_usage_usd||
       ' | monthly_usage='||us.monthly_usage_usd||
       ' | daily_window_start='||coalesce(to_char(us.daily_window_start,'YYYY-MM-DD HH24:MI:SSOF'),'-')||
       ' | weekly_window_start='||coalesce(to_char(us.weekly_window_start,'YYYY-MM-DD HH24:MI:SSOF'),'-')||
       ' | monthly_window_start='||coalesce(to_char(us.monthly_window_start,'YYYY-MM-DD HH24:MI:SSOF'),'-') AS k2
FROM user_subscriptions us
JOIN users u ON u.id=us.user_id
WHERE u.email='15858260500@163.com'
ORDER BY (us.status='active') DESC, us.id DESC;
