我必须在我的应用程序中显示总计列的运行总数...所以我使用以下查询来查找运行总计...我发现两者都按照我的需要工作.在一个我使用左连接与group by和另一个我使用子查询.
现在我的问题是,当我的数据每天增加数千时,哪一个更快,如果数据将限制在1000或2000行,那么哪一个更好......而且任何其他方法比这两个更快? ??
declare @tmp table(ind int identity(1,1),col1 int)
insert into @tmp
select 2
union
select 4
union
select 7
union
select 5
union
select 8
union
select 10
SELECT t1.col1,sum( t2.col1)
FROM @tmp AS t1 LEFT JOIN @tmp t2 ON t1.ind>=t2.ind
group by t1.ind,t1.col1
select t1.col1,(select sum(col1) from @tmp as t2 where t2.ind<=t1.ind)
from @tmp as t1
Run Code Online (Sandbox Code Playgroud) 我必须在我的表中存储年份和月份以及下个月的另外两列主题和主题详细信息我data type应该使用什么
我应该smalldatetime通过制作日期来使用和存储它们09/01/2011吗?
我应该使用两列varchar或int分别存储年份和月份2011 09吗?
我应该使用一个列varchar来存储它们,如何连接它们201109?
EDITED
有一件事我还想补充一点,我必须在搜索中使用这些列,所以我必须在where子句中使用它们所以在回答这个事情也很重要
我想显示两个日期之间的所有日期,当有任何日期数据缺失时,它应该在val列中显示为零.
declare @temp table (
id int identity(1,1) not null,
CDate smalldatetime ,
val int
)
Run Code Online (Sandbox Code Playgroud)
插入数据以检查数据
insert into @temp select '10/2/2012',1
insert into @temp select '10/3/2012',1
insert into @temp select '10/5/2012',1
insert into @temp select '10/7/2012',2
insert into @temp select '10/9/2012',2
insert into @temp select '10/10/2012',2
insert into @temp select '10/13/2012',2
insert into @temp select '10/15/2012',2
Run Code Online (Sandbox Code Playgroud)
在每月的第一天和今天之间检索记录
select * from @temp where CDate between '10/01/2012' AND '10/15/2012'
Run Code Online (Sandbox Code Playgroud)
当我运行此查询时,它显示这两个日期之间的所有数据,但我还想包括缺少日期 val=0
我想用ASP.NET 4创建一个登录但没有rememberMe复选框.有办法做到这一点吗?
当我通过其他页面发布方法发布一些html和javascript混合数据时,我的页面显示错误禁止访问错误.
但当我直接打开该页面时,它正确显示没有任何错误.
我发布数据时,我知道这是与服务器安全相关的问题.
当我搜索时,我找到了关闭mod_security的解决方案.htaccess档案.
但我想为这个页面做这个而不是我的完整网站.
我的软管环境是共享的.但我可以编辑我的.htaccess文件.
我正在使用一个Web服务,它以下列格式将数据返回到JSON
{
"responseId": 2933574,
"availableHotels": [
{
"processId": "HC-65870953",
"hotelCode": "UKI9E6",
"availabilityStatus": "InstantConfirmation",
"totalPrice": 971,
"totalTax": 0,
"totalSalePrice": 0,
"currency": "EUR",
"boardType": "Bed & Continental Breakfast",
"rooms": [
{
"roomCategory": "Triple Room",
"paxes": [
{
"paxType": "Adult",
"age": 30
},
{
"paxType": "Adult",
"age": 30
},
{
"paxType": "Child",
"age": "6"
}
],
"totalRoomRate": 486,
"ratesPerNight": [
{
"date": "2012-07-20",
"amount": 163
},
{
"date": "2012-07-21",
"amount": 163
},
{
"date": "2012-07-22",
"amount": 160
},
{
"date": "2012-07-23",
"amount": 0 …Run Code Online (Sandbox Code Playgroud) 我有以下代码在gmap上显示多个标记
<script type="text/javascript">
function init() {
var locations = [
['Bondi Beach', -33.890542, 151.274856, 4],
['Coogee Beach', -33.923036, 151.259052, 5],
['Cronulla Beach', -34.028249, 151.157507, 3],
['Manly Beach', -33.80010128657071, 151.28747820854187, 2],
['Maroubra Beach', -33.950198, 151.259302, 1]
];
var map = new google.maps.Map(document.getElementById('map'), {
zoom: 10,
center: new google.maps.LatLng(-33.92, 151.25),
mapTypeId: google.maps.MapTypeId.ROADMAP
});
var infowindow = new google.maps.InfoWindow();
var marker, i;
for (i = 0; i < locations.length; i++) {
marker = new google.maps.Marker({
position: new google.maps.LatLng(locations[i][1], locations[i][2]),
map: map
});
google.maps.event.addListener(marker, …Run Code Online (Sandbox Code Playgroud) 只想选择日期和月份的第一天之间的所有日期.我想在临时表中使用填充所有日期
declare @temp table
(
ddate datetime
)
Run Code Online (Sandbox Code Playgroud)
我尝试过 with cte ,我不想使用while循环,因为我想在存储过程中避免.
例如,就像今天一样 11-oct-2012
所以临时表应该有11行,从开始1-oct-2012到11-oct-2012
我的 cosmos db 容器中有集合项。我的示例数据是
{
"objectID": "abc",
"id": "123",
"name": "gfh",
"description": "chock",
"brand": "hcn",
"size": 180,
"sizeUnits": "Grams",
"stores": []
},
{
"objectID": "123c",
"id": "0dfg",
"name": "shaek",
"description": "7ihk",
"brand": "fghcn",
"size": 768,
"sizeUnits": "Grams",
"stores": [ {
"id": 678",
"price": 2.2
},
{
"id": 678",
"price": 2.2}]
}
Run Code Online (Sandbox Code Playgroud)
等等...
我需要获取商店为空的所有详细信息。如何为此编写查询。
我必须在where子句的基础上总结一些列,以便更好地理解我在这里实现一个临时表
declare @tbl table(a int ,b int,c int)
insert into @tbl values(1,2,3)
insert into @tbl values(2,2,3)
insert into @tbl values(1,3,1)
insert into @tbl values(1,2,3)
insert into @tbl values(1,2,3)
Run Code Online (Sandbox Code Playgroud)
并且用于找出a,b,c ob的总和a,b,c的值; 我正在使用以下查询
SELECT (
SELECT SUM(a) from @tbl where a=1
)AS a ,
(SELECT SUM(b) from @tbl where b=2
)AS b ,
(SELECT SUM(c) from @tbl where c=3
)AS c
Run Code Online (Sandbox Code Playgroud)
我问我的一个朋友对这项工作进行单行查询,他建议我按行
select sum((case when a=1 then a else null end)),
sum((case when b=2 then b else null end)),
sum((case when c=3 …Run Code Online (Sandbox Code Playgroud)