1
SELECT DISTINCT
id, name, floors, rooms, bathrooms,
singlebeds, doublebeds, tollboys, tvs,
conditontypes_id, roomtypes_id, roomstates_id,
internet, carstop, elevator, cleanservice,
phoneguide, botagaz, magazeen, maqroeev, salahdir,
clotheswasher, foodlist, makoa, thalaga, foodtable,
saala, kitchen, notations, stopstate, contract_id,
enterstate, aqed_id, aqedtype, datefrom, dateto, daynumber,
monthnumber, room_name, roomprice, cus_name, company,
discounttitle, discounttype, discountprice, total, totalend,
aqed_note, addeddate, entertime, state, nationalname,
sejelnumber, diffarest, diffbusy, dayprice, monthprice, hourprice
FROM
rooms_monitorview
WHERE
(state IS NULL) OR
(state = 'محجوز') AND (diffarest < 0)
12 102 0 0 0 0 0 0 0 1 1 1 False False False False False False False False False False False False False False False False .... False 0 شاغر NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL
14 104 0 0 0 0 0 0 0 1 1 1 False False False False False False False False False False False False False False False False .... False 0 شاغر NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL
15 105 0 0 0 0 0 0 0 1 1 1 False False False False False False False False False False False False False False False False .... False 0 شاغر 15 يومي 25/09/2017 02/10/2017 10 0 105 0.0000 سالم علي محمد بدون بدون $ 0.0000 0.0000 0.0000 ............ 22/09/2017 10:35:24 م NULL محجوز سعودي 123456 -2 -9 0.00 0.00 0.00
15 105 0 0 0 0 0 0 0 1 1 1 False False False False False False False False False False False False False False False False .... False 0 شاغر 16 يومي 28/09/2017 28/09/2017 5 0 105 0.0000 سالم علي محمد بدون بدون $ 0.0000 0.0000 0.0000 ............ 23/09/2017 01:31:21 ص NULL محجوز سعودي 123456 -5 -5 0.00 0.00 0.00
16 106 0 0 0 0 0 0 0 1 1 1 False False False False False False False False False False False False False False False False .... False 0 شاغر NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL
我需要不同的id=15
- 我該怎麼辦呢?
SELECT v.*
FROM (SELECT v.*,
ROW_NUMBER() OVER (PARTITION BY id ORDER BY id) as seqnum
FROM rooms_monitorview
WHERE (state IS NULL OR state = 'محجوز') AND diffarest < 0
) v
WHERE seqnum = 1;
注意到,我加括號的WHERE
條件:
如果你想只有一排每個ID有兩種不同的結果,-3和-9
感謝這麼多的作品精細戈登·利諾夫 –
SELECT訴* FROM(選擇我。*,ROW_NUMBER)OVER(PARTITION BY ID ORDER BY號),SEQNUM FROM rooms_monitorview(我 WHERE(狀態爲NULL) OR (state ='محجوز')AND(diffarest <0))v WHERE seqnum = 1; –