-2

我必须选择列的最小和最大年份并定义剩余年份。这可以使用 sql 查询本身来完成。我不想使用 php 代码(这将是最后一个选项)

 Give the range from (select min(Tax filing), max(Tax filing) from tax);

 //Simply writing "Define the range from(nested query)".. please give some query tags which apply.. 

在此处输入图像描述

所以它应该自动定义范围。可以使用任何查询来完成吗?

4

3 回答 3

2
select somegunk from sometable    
   where somedate between 
       (select max(year(someotherdate)) from sometable) 
   and (select min(year(someotherdate)) from sometable);
于 2013-01-09T14:48:10.913 回答
0

您可以创建一个序列表,在其中插入所有可能的值:

create table sequence (id integer not null auto_increment primary key) auto_increment=1900;

insert into  sequence values(null); -- x times

并使用此查询:

select * from sequence where id between (select min(Tax_filing) from tax) and (select max(Tax_filing) from tax);
于 2013-01-09T15:16:39.403 回答
0

如果您想列出最小年份和最大年份之间的所有年份,则应执行以下操作:

SELECT yearCol
 from yourTable
 where yearCol between
   (select min(yearCol) from yourTable)
 and
  (select max(yearCol)FROM yourTable);

您需要在 yourTable 中保存所有年份之间的记录。

于 2013-01-09T15:09:17.017 回答