我有一个查询,用于获取客人住在酒店房间的夜晚。
SELECT tm.RoomID,COUNT(tm.BookingID) AS [No Of Nights] FROM GuestRegistry tm
WHERE tm.RoomID IS NOT NULL
GROUP BY tm.BookingID,tm.RoomID
结果如下:
如何获得夜晚总数列,即72.
答案 0 :(得分:1)
With cte (roomid,NoOfNights)
As
(
SELECT tm.RoomID,COUNT(tm.BookingID) AS [NoOfNights]
FROM GuestRegistry tm WHERE tm.RoomID IS NOT NULL GROUP BY tm.BookingID,tm.RoomID
)
Select sum(NoOfNights) from CTE
答案 1 :(得分:0)
您可以执行结果的总和:
select sum([No Of Nights] ) from (
SELECT tm.RoomID,COUNT(tm.BookingID) AS [No Of Nights]
FROM GuestRegistry tm
WHERE tm.RoomID IS NOT NULL
GROUP BY tm.BookingID,tm.RoomID ) t
答案 2 :(得分:0)
<style type="text/css">
body {
margin-left: 10pt;
padding: 10pt;
}
.TimePickerWidth {
width: 150px;
}
</style>
$(document).ready(function(){
GetReservationList();
$("#btnAddUser").click(function () {
var userID = 0;
$.ajax({
type: "GET",
url: '@Url.Action("CreateEdit", "Employee")',
dataType: "html",
data: { userID: userID },
cache: false,
success: function (data) {
$("#CheckOutModalBody").html(data);
$("#CheckOutModal").modal("show");
}
});
});
});
function onAddEditUserSuccess(data) {
alert('success')
//check if the method returns a Json object.
if (typeof data == "object") {
//if yes,then check if the status is Success or Not.
if (data !== null && data.status != undefined && data.status === false) {
ShowErrorModal("Error", data.message);
} else {
$("#CheckOutModal").modal("hide");
GetReservationList();
}
} else {
$("#CheckOutModalBody").html(data);
}
}
function GetReservationList() {
$.ajax({
url: '@Url.Action("GetEmployeeList", "Employee")',
type: 'GET',
dataType: 'json',
contentType: "application/json; charset=utf-8",
beforeSend: function () { },
success: function (response, textStatus, jqXHR) {
if (response != undefined) {
DisplayExpectedArrivalList(response);
}
},
error: function (response) {
alert(response.responseText);
},
failure: function (response) {
alert(response.responseText);
}
});
}
function DisplayExpectedArrivalList(data) {
$('#propertyList').DataTable({
"scrollX": true,
destroy: true,
"processing": true,
"data": data,
"oLanguage": {
"sEmptyTable": "Sorry! No data found",
},
"columns": [
{ data: "LoginID" },
{ data: "Name" },
{ data: "password" }
],
"columnDefs": [
{
"render": function (data, type, row) {
var html = '<input type="button" id="btnEdit" onclick="AddEditUser(' + row.LoginID + ')" class="btn btn-primary bg-green" value="Edit" /> '+
'<input type="button" id="btnEdit" onclick="Delete(' + row.LoginID + ')" class="btn btn-primary bg-green" value="Delete" /> '
return html;
},
"targets": 3
}
],
"initComplete": function (settings, json) {
},
"fnDrawCallback": function (oSettings) {
}
});
}
function AddEditUser(LoginID) { alert('')
$.ajax({
type: "GET",
url: '@Url.Action("CreateEdit", "Employee")',
dataType: "html",
data: { userID: LoginID },
cache: false,
success: function (data) {
$("#CheckOutModalBody").html(data);
$("#CheckOutModal").modal("show");
GetReservationList();
}
});
}
function Delete(LoginID) {
$.ajax({
type: "POST",
url: '@Url.Action("DeleteUser", "Employee")',
dataType: "html",
data: { userID: LoginID },
cache: false,
success: function (data) {
if (data !== null && data.status == 'successfully' && data.status === false) {
alert('deleted');
}
}
});
}
<button type="button" id="btnAddUser" class="btn btn-primary" style="margin-bottom:10px">Add a new Employee</button>
<table id="propertyList" class="table table-bordered table-hover">
<thead>
<tr>
<th>
LoginID
</th>
<th>
Name
</th>
<th>
Password
</th>
<th>
Actions
</th>
</tr>
</thead>
<tbody></tbody>
</table>
<div class="modal fade" style="overflow-y: scroll;" id="CheckOutModal" tabindex="-1" role="dialog" aria-labelledby="file" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content" id="CheckOutModalBody">
</div>
</div>
</div>