select py_date as time,py_typ,py_docn,py_padtim,py_mm,py_amt from pyfile2003 where py_date in (select max(py_date) from pyfile2003 where py_com=060401 and py_typ=2 and py_mm<02 and py_status!=3 )
group by py_typ
group by py_typ
from pyfile2003
where py_date in
(select max(py_date) from pyfile2003 where py_com=060401 and py_typ=2 and py_mm<02 and py_status!=3 )
and py_typ=2 and py_mm<02 and py_status!=3
我得思路老是比较死板,你们都是高手,能否传授一下经验
----------
没看明白。
就是我得里面的sql语句取道的是一个日期值,如果已得到这个值,那么就应该写成这样:
select py_date as time,py_typ,py_docn,py_padtim,py_mm,py_amt
from pyfile2003
where py_date in
('2003-01-10 00:00:00' )
and py_typ=2 and py_mm<02 and py_status!=3,不加引号这个语句是有错误的。
SELECT py_date, py_typ, py_docn, py_padtim, py_amt
FROM pyfile2003
where py_date
in (
'2003-01-14 13:39:49'
)
and py_com = 060401
and py_typ = 2
and py_mm < 02
and py_status != 3
就能取道值。
如果是不加''就有错误,因为这个日期中间包含空格吗?
但用(select max(py_date) from 得到的本身就是日期型的,所以是不会出错的。
但你把结果填进去的话,就得加''了。
SELECT py_date, py_typ, py_docn, py_padtim, py_amt
FROM pyfile2003
where py_date
in (
select max( py_date )
FROM pyfile2003
where py_com = 060401
and py_typ = 2
and py_mm < 02
and py_status != 3
)
and py_com = 060401
and py_typ = 2
and py_mm < 02
and py_status != 3 这时mysql给我返回一个错误信息:
MySQL 返回:
You have an error in your SQL syntax near 'select max(py_date) FROM pyfile2003 where py_com=060401 and py_typ=2 and py_mm<0' at line 1
SELECT py_date, py_typ, py_docn, py_padtim, py_amt
FROM pyfile2003
where py_date
in ( select '' + max( py_date ) + ''
FROM pyfile2003
where py_com = 060401
and py_typ = 2
and py_mm < 02
and py_status != 3
)
and py_com = 060401
and py_typ = 2
and py_mm < 02
and py_status != 3
MySQL 返回:
You have an error in your SQL syntax near 'SELECT '' + max( py_date ) + '' FROM pyfile2003 where py_com = 060401 and py_typ' at line 1
要不,你去MySQL版问问看吧。
SELECT article, dealer, price
FROM shop s1
WHERE price=(SELECT MAX(s2.price)
FROM shop s2
WHERE s1.article = s2.article)
SELECT py_date, py_typ, py_docn, py_padtim, py_amt
FROM pyfile2003
where py_date
=( select max( py_date )
FROM pyfile2003
where py_com = 060401
and py_typ = 2
and py_mm < 02
and py_status != 3
)
and py_com = 060401
and py_typ = 2
and py_mm < 02
and py_status != 3
from pyfile2003
where py_date in (select max(py_date)
from pyfile2003
where py_com=060401
and py_typ=2
and py_mm<02
and py_status!=3 )
and py_typ=2 and py_mm<02 and py_status!=3
from pyfile2003
where py_date in (select max(py_date)
from pyfile2003
where py_com='060401'
and py_typ=2
and py_mm<02
and py_status!=3 )
and py_com = '060401'
and py_typ=2
and py_mm<02
and py_status!=3