mysql镶嵌查询语句提示错误1054 - Unknown column 'm.id' in 'where clause'

SELECTd.*,pm.label,(SELECTCOUNT(*)from(selectjs,jifenfromdealwhereuid=m.idandtime>DAT... SELECT d.*,pm.label,(SELECT COUNT(*) from (select js,jifen from deal where uid=m.id and time>DATE_FORMAT(time,'$Y-$d-$m') and state!=1 and state!=6 GROUP BY stoptime) as jys) from deal as d,members as m,pricemsg as pm where d.state<>1 and d.uid=m.id and d.time>DATE_SUB(now(),INTERVAL 1 MONTH) and m.username='111111111' and m.lx=1 and pm.name=d.commodity order by d.id desc

必须需要那个语句,怎么在子查询(select js,jifen from deal where uid=中等于m.id的置,求解!

CREATE TABLE `deal` (
`id` int(11) unsigned zerofill NOT NULL auto_increment,
`uid` int(11) NOT NULL,
`time` datetime NOT NULL,
`type` int(11) NOT NULL,
`commodity` varchar(255) NOT NULL,
`class` varchar(255) NOT NULL,
`price` double NOT NULL,
`jifen` double(11,2) NOT NULL,
`stoptime` datetime NOT NULL,
`stopprice` double default '0',
`js` double(11,2) default NULL,
`state` int(11) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=96 DEFAULT CHARSET=gb2312;
32) NOT NULL,
`lx` int(11) NOT NULL,
`name` varchar(20) NOT NULL,
`sex` char(1) NOT NULL,
`phone` char(11) NOT NULL,
`phonev` char(1) default NULL,
`email` varchar(50) NOT NULL,
`emailev` char(1) default NULL,
`regtime` datetime NOT NULL,
`regip` varchar(255) NOT NULL,
`jifen` double(11,2) NOT NULL default '0.00',
`je` double(11,2) NOT NULL default '0.00',
`viptime` datetime default NULL,
`tj` int(11) default NULL,
PRIMARY KEY (`id`,`username`)
) ENGINE=InnoDB AUTO_INCREMENT=17 DEFAULT CHARSET=gb2312;
CREATE TABLE `pricemsg` (
`name` varchar(255) NOT NULL,
`label` varchar(255) NOT NULL,
`class` varchar(255) default NULL,
`win` int(3) NOT NULL default '85',
`loss` int(3) NOT NULL default '15',
`price` double default NULL,
PRIMARY KEY (`name`)
) ENGINE=InnoDB DEFAULT CHARSET=gb2312;
展开
 我来答
百度网友bbe3b5a
2019-07-19 · TA获得超过1116个赞
知道答主
回答量:16
采纳率:0%
帮助的人:4689
展开全部

源代码如下:

SELECT d.*,pm.label,
( SELECT COUNT(*)
from (select js,jifen
from deal


where uid=m.id and time>DATE_FORMAT(time,'$Y-$d-$m')


and state!=1 and state!=6 GROUP BY stoptime

)


) as jys


from deal as d,members as m,pricemsg as pm


where d.state<>1 and d.uid=m.id and d.time>DATE_SUB(now(),INTERVAL 1 MONTH)


and m.username='111111111' and m.lx=1 and pm.name=d.commodity


order by d.id desc

运行结果如下:

扩展资料:

mysql的另一种查询方式-嵌套查询表达形式

SELECT <目标表达式1>[,...]

FROM <表或视图名1>

WHERE [表达式] (SELECT <目标表达式2>[,...]

FROM <表或视图名2>)

[GROUP BY <分组条件>

HAVING [<表达式>比较运算符] (SELECT <目标表达式2>[,...]

FROM <表或视图名2> )]

1、返回一个值的子查询

当子查询的返回值只有一个时,可以使用比较运算符如=、<、>、>=、<=、!=等将富查询和子查询连接起来。

2、返回一组值的子查询

如果子查询的返回值不止一个,而是一个集合时,则不能直接使用比较运算符,可以在比较运算符和子查询之间插入ANY、SOME或ALL。其中等值关系可以用IN操作符。

扩展资料来源:百度百科-嵌套查询

小狂中E
2013-10-31 · TA获得超过1418个赞
知道大有可为答主
回答量:1514
采纳率:66%
帮助的人:1038万
展开全部
SELECT d.*,pm.label,
( SELECT COUNT(*)
from (select js,jifen
from deal
where uid=m.id and time>DATE_FORMAT(time,'$Y-$d-$m')
and state!=1 and state!=6 GROUP BY stoptime
)
) as jys
from deal as d,members as m,pricemsg as pm
where d.state<>1 and d.uid=m.id and d.time>DATE_SUB(now(),INTERVAL 1 MONTH)
and m.username='111111111' and m.lx=1 and pm.name=d.commodity
order by d.id desc
追问
依旧: Unknown column 'm.id' in 'where clause'
追答
实在是没看懂那个子查询
select js,jifen
from deal
where uid=m.id and time>DATE_FORMAT(time,'$Y-$d-$m') and state!=1 and state!=6
GROUP BY stoptime
既然按stoptime分组,咋能选出js与jifen呢
本回答被提问者采纳
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式