我正在尝试执行查询:
select d1.rtime, d2.rtime,
(d2.time_on_auto - d1.time_on_auto) as delta1,
(d2.time_on_zal - d1.time_on_zal) as delta2
from (select *
from db_reso3f_operation_month
where rtime = '2013-02-01' AND gateway_id = 11226 AND f2 = 2 AND f1 = 4
) d1 cross join
(select *
from db_reso3f_operation_month
where rtime = '2013-03-01' AND gateway_id = 11226 AND f2 = 2 AND f1 = 4
) d2
当我在DB编辑器中执行它时(我正在使用PgAdmin),它会返回正确的结果。但是当我尝试使用ExecuteReader()执行它时,没有返回任何结果。它的代码如下所示:
using (NpgsqlCommand dbCommand = DBConnection.CreateCommand())
{
string sql1 = string.Format(@"select d1.rtime, d2.rtime," +
"(d2.time_on_auto - d1.time_on_auto) as delta1," +
"(d2.time_on_zal - d1.time_on_zal) as delta2" +
" from (select *" +
" from db_reso3f_operation_month" +
" where rtime = '2013-02-01' AND gateway_id = {0} AND f2 = {1} AND f1 = {2}" +
") d1 cross join" +
"(select *" +
"from db_reso3f_operation_month" +
" where rtime = '2013-03-01' AND gateway_id = {0} AND f2 = {1} AND f1 = {2}" +
") d2",
device.GatewayId,
device.F2,
device.ReferenceCircuit);
dbCommand.CommandText = sql1;
using (IDataReader dataReader = dbCommand.ExecuteReader())
{
while (dataReader.Read())
{
switchedOnTime += (int)dataReader["delta1"];
switchedOnTime += (int)dataReader["delta2"];
}
}
我现在不知道问题是什么,以及找不到有关npgsql是否支持此类查询的任何信息。