我很困惑为什么我无法在drop table hist_loads
drop table hist_exproot
drop table hist_eqmtlist
GO
create table hist_loads
(
shiftindex int,
truck int,
measureton decimal(18,2),
--,AVG(measureton) as measureton
--,COUNT(excav) as loads
excav int
)
create table hist_exproot
(
shiftindex int,
shiftdate date,
)
create table hist_eqmtlist
(
shiftindex int,
eqmtid int, -- hl.truck = heq.eqmtid
eqmttype varchar(100) --in ('Euclid EH4500','Euclid EH4500-W','Euclid EH4500-HW')
)
GO
insert into hist_loads values
(1,1,100,1)
,(2,1,200,1)
,(3,1,300,1)
,(4,1,100,1)
,(5,1,200,1)
,(6,1,300,1)
,(7,1,100,1)
,(8,1,200,1)
,(9,1,300,1)
,(10,1,100,1)
,(11,1,200,1)
,(12,1,300,1)
,(13,2,300,1)
,(14,2,295,1)
,(15,2,295,1)
,(16,2,300,1)
,(17,2,295,1)
,(18,2,295,1)
,(19,2,300,1)
,(20,2,295,1)
,(21,2,295,1)
,(22,2,300,1)
,(23,2,295,1)
,(24,2,295,1)
,(25,2,300,1)
,(26,2,295,1)
,(27,2,295,1)
,(28,3,300,1)
,(29,3,300,1)
,(30,3,300,1)
,(31,3,300,1)
,(32,3,300,1)
,(33,3,300,1)
,(34,3,300,1)
,(35,3,300,1)
,(36,3,300,1)
,(37,3,300,1)
,(38,3,300,1)
,(39,3,300,1)
,(40,3,300,1)
,(41,3,300,1)
,(42,3,300,1)
,(43,4,999,1)
insert into hist_exproot values
(1,'2017-12-05')
,(2,'2017-12-05')
,(3,'2017-12-05')
,(4,'2017-12-05')
,(5,'2017-12-05')
,(6,'2017-12-05')
,(7,'2017-12-05')
,(8,'2017-12-05')
,(9,'2017-12-05')
,(10,'2017-12-05')
,(11,'2017-12-05')
,(12,'2017-12-05')
,(13,'2017-12-05')
,(14,'2017-12-05')
,(15,'2017-12-05')
,(16,'2017-12-05')
,(17,'2017-12-05')
,(18,'2017-12-05')
,(19,'2017-12-05')
,(20,'2017-12-05')
,(21,'2017-12-05')
,(22,'2017-12-05')
,(23,'2017-12-05')
,(24,'2017-12-05')
,(25,'2017-12-05')
,(26,'2017-12-05')
,(27,'2017-12-05')
,(28,'2017-12-05')
,(29,'2017-12-05')
,(30,'2017-12-05')
,(31,'2017-12-05')
,(32,'2017-12-05')
,(33,'2017-12-05')
,(34,'2017-12-05')
,(35,'2017-12-05')
,(36,'2017-12-05')
,(37,'2017-12-05')
,(38,'2017-12-05')
,(39,'2017-12-05')
,(40,'2017-12-05')
,(41,'2017-12-05')
,(42,'2017-12-05')
,(43,'2017-12-05')
insert into hist_eqmtlist values
(1,1,'Euclid EH4500')
,(2,1,'Euclid EH4500')
,(3,1,'Euclid EH4500')
,(4,1,'Euclid EH4500')
,(5,1,'Euclid EH4500')
,(6,1,'Euclid EH4500')
,(7,1,'Euclid EH4500')
,(8,1,'Euclid EH4500')
,(9,1,'Euclid EH4500')
,(10,1,'Euclid EH4500')
,(11,1,'Euclid EH4500')
,(12,1,'Euclid EH4500')
,(13,2,'Euclid EH4500-W')
,(14,2,'Euclid EH4500-W')
,(15,2,'Euclid EH4500-W')
,(16,2,'Euclid EH4500-W')
,(17,2,'Euclid EH4500-W')
,(18,2,'Euclid EH4500-W')
,(19,2,'Euclid EH4500-W')
,(20,2,'Euclid EH4500-W')
,(21,2,'Euclid EH4500-W')
,(22,2,'Euclid EH4500-W')
,(23,2,'Euclid EH4500-W')
,(24,2,'Euclid EH4500-W')
,(25,2,'Euclid EH4500-W')
,(26,2,'Euclid EH4500-W')
,(27,2,'Euclid EH4500-W')
,(28,3,'Euclid EH4500-HW')
,(29,3,'Euclid EH4500-HW')
,(30,3,'Euclid EH4500-HW')
,(31,3,'Euclid EH4500-HW')
,(32,3,'Euclid EH4500-HW')
,(33,3,'Euclid EH4500-HW')
,(34,3,'Euclid EH4500-HW')
,(35,3,'Euclid EH4500-HW')
,(36,3,'Euclid EH4500-HW')
,(37,3,'Euclid EH4500-HW')
,(38,3,'Euclid EH4500-HW')
,(39,3,'Euclid EH4500-HW')
,(40,3,'Euclid EH4500-HW')
,(41,3,'Euclid EH4500-HW')
,(42,3,'Euclid EH4500-HW')
,(43,4,'Euclid EH4500-HW')
GO
declare @dateIni date, @dateEnd date = getdate()
set @dateIni = dateadd(day,-3,@dateEnd)
select *
into #temp_loads
from
(
select
hl.truck
,AVG(hl.measureton) as avg_measureton
,COUNT(hl.excav) as loads
from hist_loads hl
join hist_exproot hex on hex.shiftindex = hl.shiftindex
where
hex.shiftdate between @dateIni and @dateEnd
and exists (select * from hist_eqmtlist heq where heq.eqmtid = hl.truck and heq.eqmttype in ('Euclid EH4500','Euclid EH4500-W','Euclid EH4500-HW')) -- not a join because cannot be sure of the table correlation and data sanity
group by hl.truck
) as ld
where ld.loads >= 10
declare @average_measureton decimal = (select AVG(avg_measureton) from #temp_loads)
declare @treshould decimal = @average_measureton -(@average_measureton/20.0)
select @average_measureton, @treshould
select tl.truck, tl.avg_measureton, hex.shiftdate
from #temp_loads tl
join hist_eqmtlist heq on heq.eqmtid = tl.truck
join hist_exproot hex on hex.shiftindex = heq.shiftindex
where tl.avg_measureton > @treshould
and hex.shiftdate between @dateIni and @dateEnd
-- you can repeat the truck type test here but it's not necessary, lef tit at the aggregation for performance
drop table #temp_loads
中获得任何值。
我的代码中有什么问题..
这里是代码..
cursor
我在上面代码的最后三行有 sqLiteDatabase = getReadableDatabase();
Cursor cursor = sqLiteDatabase.query("bank",new String[]{"name", "acno", "available"},"bank_index = ?",new String[]{String.valueOf(bank_index)},null,null,null);
cursor.moveToFirst();
String name = cursor.getString(cursor.getColumnIndex("name"));
String acno = cursor.getString(cursor.getColumnIndex("acno"));
contentValues.put("bank", name + " Account number: " + acno);
错误。
查询表:
CursorOutOfBoundsException
答案 0 :(得分:1)
在对光标执行任何操作之前,您必须检查
if(cursor != null && cursor.getCount() > 0 ) {
//go ahead
}
//You can also try
String query = "SELECT name, acno, available FROM bank WHERE bank_index = '"+String.valueOf(bank_index)+"'";
Cursor cursor = sqLiteDatabase.rawQuery(query,null);