如何在初始三个月/年和最后三个月/年之间选择MySQL中的行?

时间:2016-09-05 02:46:29

标签: mysql sql

该表具有以下结构:

library('ks')
library('raster')

# generate the data
set.seed(1)
x = matrix(rnorm(1000,1,0.5),500)

xpix = 100
ypix = 100

# calculate the density function
k = kde(
    x,
    H=matrix(c(0.1,0,0,0.1),2),
    xmin=c(0,0),
    xmax=c(1,1),
    gridsize=c(xpix,ypix)
)
# convert to raster
r = raster(k)
# plot the image to PNG
png('file.png',width=xpix,height=ypix)
    par(
        mar=c(0,0,0,0),
        bty='n',
        bg='black',
        plt=c(0,1,0,1)
    )
    plot(
        r,
        legend=FALSE,
        axes=FALSE,
        plt=c(0,1,0,1)
    )
    # see that 'plt' did not change
    print(par())
dev.off()

现在我要选择2014年第3学期和2016年第1学期之间的所有项目,你怎么能这样做?

使用此示例表进行查询的结果可能是:

code | item | trimester | year
1       rrr      1         2014
2       fff      3         2014
3       ggg      3         2014
4       hhh      4         2015
5       ttt      2         2016
6       fff      3         2016

1 个答案:

答案 0 :(得分:1)

一种方法:

where year * 10 + trimester between 20143 and 20161

或者,您可以明确:

where (year > 2014 or (year = 2014 and trimester >= 3)) and
      (year < 2016 or (year = 2016 and trimester = 1))