Search code examples
minimum

Get min value for first date


everyone.

I'm busy creating a reporting view in SQL, but I'm struggling a bit with some logic I need. I have:

  • SubscriberID
  • MSISDN
  • ICCID
  • VOUCHERCODE
  • RECHARGEDATE

I need to find the first date a voucher was bought, as well as the value of that voucher. The SubscriberID, MSISDN and ICCID fields form a 'unique key'.

I'm just struggling to figure out how to display first date and first voucher. There are several vouchers for instance on the first date. I'm completely lost.

I've got:

> select subscriberid, MSISDN, ICCID, 'first'(VoucherCode),
> 'first'(RECHARGEDATE) from table

That returns more than one row. I need a single row. Any help would be greatly appreciated!


Solution

  • It turns out I wasn't using to_date() on the recharge date. It's working now.