How to get max count of foreign key SQL Server -
i have 2 tables
noroom varchar(50) primary key, kindroom nvarchar(50), price float, pricecurrent float, r_status nvarchar(50), nametour nvarchar(50), checkin date, checkout date, company nvarchar(50), idroom nvarchar(50) foreign key references rooms(noroom)
and here code
select rooms.noroom, rooms.kindroom, count(checkintour.idroom) numberoforder rooms left join checkintour on( rooms.noroom = checkintour.idroom ) group rooms.noroom, rooms.kindroom order numberoforder desc
output this
+-----------+----------+----------------+ | no room | kindroom | numberoforder | +-----------+----------+----------------+ | po0051 vip 1 | po0053 single 1 | po0054 vip 1 | po0055 vip 1 | po0056 vip 1 | po0057 vip 1 | po0058 vip 1 | po0059 vip . | po0060 . .. | po0061 .. ... | po0062 | | | | | | | | | | | +-----------+----------+----------------+
how can max numberoforder ? other word, if type of room vip want sum numbersof order of room
select rooms.noroom, rooms.kindroom, count(checkintour.idroom) numberoforder checkintour join rooms on rooms.noroom = checkintour.idroom group rooms.noroom, rooms.kindroom order checkintour.idroom desc
Comments
Post a Comment