DBからデータを取得できますが、各日付に1行しか必要でないことを除けば、下の図の例では2行目のみにする必要があります最初のものではありません。私はどうにかして、1つの日付から1人のユーザーに対して1行しか取得できないようにする必要があります。最新の日時を持つユーザごとに行を選択
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
とROWNUMBER = 1 –