English 中文(简体)
比较若干日期
原标题:Query for compare several dates
  • 时间:2011-10-11 20:32:46
  •  标签:
  • sql

I need compare some dates, my query is getting 3 dates in first query => 2011-09-01, 2011-10-01, 2011-11-01

And 3 dates in second query => 2011-07-01, 2011-11-01, 2011-08-01

因此,我如何比较这些错误,避免这种错误:

Subquery 退回了不止一种价值,在以下数值时,这种价值是不正确的: = ,andlt;=,>> = Or when used as an expression

增 编

SELECT 
 c_Fk_IdBoleta as Numero_Boleta,
  Pregunta (12)  as Numero_Pregunta,
  El período transcurrido entre siembra y cosecha no corresponde al tipo de cultivo  as Detalle_Error
  FROM
    Clt_Sembrado as sembrado
  WHERE
     sembrado.c_Fk_IdBoleta = 45550711
    GROUP BY sembrado.c_Fk_IdBoleta, sembrado.d_MesAnioSiembra, sembrado.d_MesAnioCosecha, sembrado.si_Fk_IdDesglose
    HAVING 
   ( SELECT  sembrado.d_MesAnioCosecha 
   FROM Clt_Sembrado as sembrado, Clt_Desglose as desglose 
   WHERE sembrado.si_Fk_IdDesglose = desglose.si_Pk_IdDesglose 
   AND sembrado.c_Fk_IdBoleta = 45550711
   )                                                           >           (SELECT DATEADD(Month,6,sembrado.d_MesAnioSiembra)
                                                                            FROM Clt_Desglose as desglose, Clt_Sembrado as sembrado
                                                                            WHERE (((sembrado.si_Fk_IdDesglose = desglose.si_Pk_IdDesglose)AND
                                                                            (desglose.c_Fk_CodCiiu4 = 0112.00
                                                                            OR desglose.c_Fk_CodCiiu4 = 0111.01
                                                                            OR desglose.c_Fk_CodCiiu4 = 0111.02
                                                                            OR desglose.c_Fk_CodCiiu4 = 0113.01
                                                                            OR desglose.c_Fk_CodCiiu4 = 0113.03
                                                                            OR desglose.c_Fk_CodCiiu4 = 0113.05
                                                                            OR desglose.c_Fk_CodCiiu4 = 0113.06
                                                                            OR desglose.c_Fk_CodCiiu4 = 0113.07
                                                                            OR desglose.c_Fk_CodCiiu4 = 0113.08
                                                                            OR desglose.c_Fk_CodCiiu4 = 0113.10                            
                                                                            ))
                                                                            AND sembrado.c_Fk_IdBoleta = 45550711))

下表: 问题在于在表Blt_Sembrado中可以插入“一”或“二读”时间,我需要证实,“MesAnioCosecha”的情况较少(d_MesioAnSiembra + 6个月)。 页: 1

“entergraph

问题回答

你的问题是:

AND sembrado.c_fk_idboleta = 40480711) > (SELECT ...

为了完成这项工作,你必须确保你的分选能够以多数价值回报。

如果你的日期必须大于所交回的所有日期,那么,这个日期与所交回的最高日期相同,因此,使用<条码><<>/条码>解决你的问题:

AND sembrado.c_fk_idboleta = 40480711) > (SELECT 
   Dateadd(MONTH, 6, max(sembrado.d_mesaniosiembra))
...




相关问题
SQL SubQuery getting particular column

I noticed that there were some threads with similar questions, and I did look through them but did not really get a convincing answer. Here s my question: The subquery below returns a Table with 3 ...

难以执行 REGEXP_SUBSTR

I m 查询Oracle 10g。 我有两张表格(样本数据见下文)。 i m 试图提取一些领域

SQL Query Shortcuts

What are some cool SQL shorthands that you know of? For example, something I learned today is you can specify to group by an index: SELECT col1, col2 FROM table GROUP BY 2 This will group by col2

PHP array callback functions for cleaning output

I have an array of output from a database. I am wondering what the cleanest way to filter the values is example array Array ( [0] => Array ( [title] => title 1 ...

OracleParameter and DBNull.Value

we have a table in an Oracle Database which contains a column with the type Char(3 Byte). Now we use a parameterized sql to select some rows with a DBNull.Value and it doesn t work: OracleCommand ...

Running numbers in SQL

I have a SQL-statement like this: SELECT name FROM users WHERE deleted = 0; How can i create a result set with a running number in the first row? So the result would look like this: 1 Name_1 2 ...

How to get SQL queries for each user where env is production

I’m developing an application dedicated to generate statistical reports, I would like that user after saving their stat report they save sql queries too. To do that I wrote the following module: ...

热门标签