Posts

Showing posts with the label group-by

finding highest total price and converting

finding highest total price and converting So I have to use a query where I list the trade id stock id and the total price converted to us dollars where it is the highest price total. SELECT tr.trade_id, tr.stock_id, round(tr.price_total * con.exchange_rate,2) as "US Dollars" from trade tr JOIN stock_exchange se on se.STOCK_EX_ID = tr.STOCK_EX_ID JOIN currency curr on curr.CURRENCY_ID = se.currency_id JOIN conversion con on con.from_CURRENCY_ID = curr.CURRENCY_ID WHERE (tr.PRICE_TOTAL) = (Select Max(price_total) from trade) and curr.name = 'Dollar' and tr.stock_ex_id is not NULL group by tr.trade_id, tr.stock_id, round(tr.price_total), tr.price_total, round(tr.price_total * con.exchange_rate,2); Trade (trade_id PK, stock_id FK2, transaction_time, shares, stock_ex_id FK1,price_total) Stock-exchange( stock_ex_id PK, name, symbol, currency_id FK1) conversion( from_currency_id PK, to_currency_id) currency ( currency_id PK, name, symbol expected output should be - trade_...

how to extend date by specific condition

how to extend date by specific condition query to extend the valid_till date for a month of tenants who have referred more than two times sample data: ref_id referrer_id referrer_bonus_amount referral_valid valid_from valid_till 263 5 2500 1 2015-07-05 2015-09-05 264 3 2500 1 2015-07-05 2015-09-05 265 5 1000 0 2015-12-13 2016-02-13 266 6 2500 0 2016-04-25 2016-06-24 267 10 1000 1 2015-07-01 2015-09-01 268 5 2500 1 2015-05-12 2015-07-12 269 10 2500 0 2015-08-05 2015-10-05 what I want is to increase valid_till date of referrer_id who has referred more than twice. To get who has referred more than 2 times I'm using this code: > select referrer_id > from Referrals group by referrer_id having count(referrer_id)>2 but how to add one month for referrer_id >2 in valid_till column. I believe dateadd is to be used but i couldnt figure out how. 3 Answers ...