列出计算机类图书的名称及价格.最后求出册数和总价格。
select 书名,定价
from 图书
where 类别='计算机'
union
select count('计算机'),sum(定价)
from 图书
where 类别='计算机'
group by 类别
显示结果
将 varchar 值 '数据库系统教程 ' 转换为数据类型为 int 的列时发生语法错误。
列出计算机类图书的名称及价格.最后求出册数和总价格。
select 书名,定价
from 图书
where 类别='计算机'
union
select count('计算机'),sum(定价)
from 图书
where 类别='计算机'
group by 类别
显示结果
将 varchar 值 '数据库系统教程 ' 转换为数据类型为 int 的列时发生语法错误。
你对union的理解可能是不正确的吧?
我觉得应该这么做
select t.书名, t.定价, t.count as 册数, (t.count * t.定价) as 总价格
select 书名,定价,count('书名') as count
from 图书
where 类别='计算机'
group by 类别,书名
) t