谢谢shetianlang的答复但是我在本地(mysql4.1.7)下面的语句运行正常,但往服务器(mysql5.0)传,时提示 exists 有错误. select (case when not exists(select 1 from temp where a.shopid=shopid and productname<a.productname) then shopid else ' ' end)AS shopid, shopname, shopadmin,mode,productname,ordertime,state,prodcuts_price, email,dress,tel,(sum(row))as row from temp a group by shopid,productname,prodcuts_price
show:#1064 - You have an error in your SQL syntax near 'exists(select 1 from temp where a.shopid=shopid and productname<a.productname) ' at line 1
你的group by 错了,应该是这样的: group by shopname,shopadmin,mode,productname,ordertime,state,prodcuts_price,email,dress,tel
我按 lllyyymmm(傻貓) 说的试了,不对错误提示还是上面的那个
用法如下: lz自己参考 select A.* from 表1 A where exists(select 1 from 表2 where 主键=A.主键)
如下:
where exists
(select 1 from
select (case when not exists(select 1 from temp where a.shopid=shopid and productname<a.productname) then shopid
else ' ' end)AS shopid,
shopname,
shopadmin,mode,productname,ordertime,state,prodcuts_price,
email,dress,tel,(sum(row))as row from temp a
group by shopid,productname,prodcuts_price
group by shopname,shopadmin,mode,productname,ordertime,state,prodcuts_price,email,dress,tel
lz自己参考
select A.*
from 表1 A
where exists(select 1 from 表2 where 主键=A.主键)