The error I get after putting in the query builder is:
invalid SQL statement; expected 'DELETE', 'INSERT', 'PROCEDURE', 'SELECT', or 'UPDATE'
this is the over all code that I believe should work on SQL server,
Code:
WITH WIN (suid, iid, stime, price, nbids) as
(SELECT bid.seller, bid.iid, bid.starttime, max(bid.bidprice), count(*) as nBIDs
FROM auction INNER JOIN bid ON (auction.seller = bid.seller) and (auction.iid = bid.iid) and (auction.startdate = bid.starttime)
WHERE bid.bidtime < auction.enddate AND bid.bidprice >= auction.minbid AND now >=auction.enddate
GROUP BY bid.seller, bid.iid, bid.starttime)
WITH WINdetails (buid, suid, iid, stime, sprice, nbids, btime ) as
(SELECT b.bidder, w.suid, w.iid, w.stime, w.sprice, w.nbids, b.bidtime
FROM WIN W INNER JOIN BID B WHERE w.sprice = b.bidprice)
SELECT iid from WINDETAILS WHERE now - enddate < 7
What I am trying to do is find the person who won the bid within the last week.
This code below finds the first part ("all the person who won the bid") but it doesn't set the criteria within the last week.
Code:
SELECT bid.seller, bid.iid, bid.starttime, max(bid.bidprice), count(*) as nBIDs
FROM auction INNER JOIN bid ON (auction.seller = bid.seller) and (auction.iid = bid.iid) and (auction.startdate = bid.starttime)
WHERE bid.bidtime < auction.enddate AND bid.bidprice >= auction.minbid AND now >=auction.enddate
GROUP BY bid.seller, bid.iid, bid.starttime
this code below is suppose to limit them to the items that were sold last week.
Code:
SELECT iid from WINdetails WHERE now - enddate < 7
The code you provided is actually not similar to the first one I put up, because the one I put up is using variable to represent all the fields,
example:
WITH WIN (suid, iid, stime, price, nbids) as
bid.seller = suid
bid.iid = iid
bid.starttime = stime
max(bid.bidprice) = price
and count(*) = nbids
Here is the sample data, highlighted in yellow, the bottom row is the winning bid because it's the highest bid price.