sql语句
select sbzt,ip,
sblx,
sbxml,
replace(substr(to_char(xgsj, 'yyyy-mm-dd-hh24-mi-ss'), 12, 8),
'-',
'') as A
from SJSB_SSRE
where to_char(cjsj, 'yyyy-mm-dd') >'2021-12-06'
and to_char(cjsj, 'yyyy-mm-dd') <'2021-12-10'
and sblx = '3'
and sbzt = '3'
and ip = '172.21.188.10'and A>‘’
想把查询出来的A当做一个限制条件。 目前我知道A是不能放where后面。就是想达到类似的效果,要怎么做啊。 SELECT * FROM
(select sbzt,
ip,
sblx,
sbxml,
replace(substr(to_char(xgsj, 'yyyy-mm-dd-hh24-mi-ss'), 12, 8),
'-',
'') as A
from SJSB_SSRE
where to_char(cjsj, 'yyyy-mm-dd') >'2021-12-06'
and to_char(cjsj, 'yyyy-mm-dd') <'2021-12-10'
and sblx = '3'
and sbzt = '3'
and ip = '172.21.188.10' )WHERE A>‘’ 你这个sql语句怎么写那么多条件,看着眼晕。一般遇到这种情况我都用框架调用。简单明了 按道理日期直接不用这么麻烦,再转成字符串
select sbzt,
ip,
sblx,
sbxml,
replace(substr(to_char(xgsj, 'yyyy-mm-dd-hh24-mi-ss'), 12, 8),
'-',
'') as A
from SJSB_SSRE
where to_char(cjsj, 'yyyy-mm-dd') >'2021-12-06'
and to_char(cjsj, 'yyyy-mm-dd') <'2021-12-10'
and sblx = '3'
and sbzt = '3'
and ip = '172.21.188.10'
and replace(substr(to_char(xgsj, 'yyyy-mm-dd-hh24-mi-ss'), 12, 8),
'-',
'') >‘’ 不能扔where后边,试试能不能扔having后边 select * from ( select sbzt,
ip,
sblx,
sbxml,
replace(substr(to_char(xgsj, 'yyyy-mm-dd-hh24-mi-ss'), 12, 8),
'-',
'') as A
from SJSB_SSRE ) t
where to_char(t.cjsj, 'yyyy-mm-dd') >'2021-12-06'
and to_char(t.cjsj, 'yyyy-mm-dd') <'2021-12-10'
and t.sblx = '3'
and t.sbzt = '3'
and t.ip = '172.21.188.10'and t.A>'' 在外面再加一层select,把查出来的结果作为一个表,A作为一个字段,重新select,A字段就可以作为一个条件使用了
select sbzt,
ip,
sblx,
sbxml,
replace(substr(to_char(xgsj, 'yyyy-mm-dd-hh24-mi-ss'), 12, 8),
'-',
'') as A
from SJSB_SSRE
where to_char(cjsj, 'yyyy-mm-dd') >'2021-12-06'
and to_char(cjsj, 'yyyy-mm-dd') <'2021-12-10'
and sblx = '3'
and sbzt = '3'
and ip = '172.21.188.10'
having A>‘’ SELECT ... FROM SJSB_SSRE, A WHERE A.??> ...
页:
[1]
2