gpt4 book ai didi

sql - 每个用户选择当天最晚时间的行

转载 作者:行者123 更新时间:2023-11-29 14:37:17 27 4
gpt4 key购买 nike

<分区>

我能够从我需要的数据库中获取数据,除了每个日期我只想要一行,所以例如在下图中应该只有第二行而不是第一行。我不知何故需要能够从一个日期为一个用户获取一行。

SELECT id_user, date_created || ' ' || time_created as placed
FROM (
SELECT
b_objednavky.uzivatel AS id_uzivatele,
b_objednavky.vytvoreno::date AS date_created,
to_char(b_objednavky.vytvoreno, 'HH24:MI:SS') as time_created,
b_objednavky.created

FROM b_objednavky
INNER JOIN u_uzivatele ON b_objednavky.uzivatel = (
SELECT u_uzivatele.id from u_uzivatele JOIN bw_paid_orders
ON u_uzivatele.id = bw_paid_orders.user_id
WHERE bw_paid_orders.active_thru < NOW() + interval '6 months'
) uzivatele
INNER JOIN bc_stavy_objednavky ON b_objednavky.stav = bc_stavy_objednavky.id

WHERE bc_stavy_objednavky.sysid = 'nova' AND b_objednavky.vytvoreno <= NOW()
AND bc_staty.kod NOT IN (
'BR', 'CL', 'AR', 'MX'
)

) AS order
LEFT OUTER JOIN (
SELECT user_id, max(paid) as last_paid FROM bw_paid_orders
GROUP BY user_id
) last_paid_by_user ON (id_user = user_id)
WHERE (created > last_paid OR last_paid IS NULL) AND created BETWEEN ('2017-02' || '-01')::date
AND ('2017-02' || '-01')::DATE + '1 month'::interval
ORDER BY datum_objednani DESC, objednavajici, nazev, duration

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com