请教一个SQL语句,高手看看!

lijun_shu 2003-09-18 10:14:58
一个表:
item color amount
a red 20
a blue 35
b red 16
b blue 13
怎么用SQL语句现实红色数目大于蓝色的item,并显示差直
...全文
60 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
伍子V5 2003-09-25
  • 打赏
  • 举报
回复
select a.item,(a.amount-b.amount) as 差值 from
(
select * from 表 where color='red'
)a,
(
select * from 表 where color='blue'
)b
where a.item=b.item and a.amount>b.amount

vrv0129 2003-09-25
  • 打赏
  • 举报
回复
select a.amount-b.amount from(select * from table where color=rde)a,(select * from table where color=blue)b where a.amount>b.amount
ezhou 2003-09-23
  • 打赏
  • 举报
回复
要解决这个问题,要应用一个技巧,要给这一个表取两个别名,这样就容易多了。
yoki 2003-09-19
  • 打赏
  • 举报
回复
select a.item,(a.amount-b.amount) as 差值 from
(
select * from 表 where color='rde'
)a,
(
select * from 表 where color='blue'
)b
where a.item=b.item and a.amount>b.amount
happy_0325 2003-09-19
  • 打赏
  • 举报
回复
select a.item from table a,table b where a.item=b.item and a.color='red' and b.color='blue' and a.amount>b.amount
huahaoyueyuan 2003-09-19
  • 打赏
  • 举报
回复
select a.item,a.amount from 表 a,表 b where a.item<>b.item
我的思路是同一个表起两个不同的别名,这样就相当于一个表了,查询这两个表中记录item不相等的记录不就行了吗

6,107

社区成员

发帖
与我相关
我的任务
社区描述
其他数据库开发 数据库报表
社区管理员
  • 数据库报表社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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