同求一条sql

zecool20 2012-08-24 10:54:27

create table x(
id tinyint(5) unsigned not null auto_increment,
name char(25) not null default '',
price DECIMAL(4,2) unsigned not null default '0',
primary key(id),
unique key name(name)
)engine=myisam default charset=utf8
insert into x(id,name,price)values(null,'冰红茶',3.5);
insert into x(id,name,price)values(null,'电饭锅',99);
create table y(
id tinyint(5) unsigned not null auto_increment,
individual tinyint(5) unsigned not null,
primary key(id)
)engine=myisam default charset=utf8
insert into y(id,individual)values(null,4);
insert into y(id,individual)values(null,2);


查询输出结果要这样:212 = 14+198
...全文
49 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
zecool20 2012-08-25
  • 打赏
  • 举报
回复
结果还是不对,还差一点点。。。
+---------------------------------------------------------------------------------------------+
| concat(sum(x.price*y.individual),'=',x.price,'*',y.individual,'+',x.price,'*',y.individual) |
+---------------------------------------------------------------------------------------------+
| 212.00=3.50*4+3.50*4 |
+---------------------------------------------------------------------------------------------+
ACMAIN_CHM 2012-08-25
  • 打赏
  • 举报
回复
select sum(x.price*y.individual)
from x,y
where x.id=y.id

56,678

社区成员

发帖
与我相关
我的任务
社区描述
MySQL相关内容讨论专区
社区管理员
  • MySQL
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧