有个表如下:no qty
1 3
1 4
2 1
2 2
3 5
3 4
4 3
--------------------------------
需要的结果:把no相同的qty * qty
no qty
1 12
2 2
3 20
4 3
1 3
1 4
2 1
2 2
3 5
3 4
4 3
--------------------------------
需要的结果:把no相同的qty * qty
no qty
1 12
2 2
3 20
4 3
解决方案 »
- 如何用STRINGGRID显示数据库中表的完整数据信息?
- 主从表的操作的问题?
- 怎样读取silverlight
- 如何完全清楚DBRichEdit中的记录?????
- 问题困我从学delphi到现在,都没办法搞定,请做过"进销库"的朋友进来看看,实现狠简单的事的query
- 用NMSMTP做MAIL时,怎样根据邮箱名得到它的SMTP服务器名称啊?欢迎光临!!
- Delphi 中实现不精确查找!
- 要多少分,请开口!!(MAX=8410):如何在发送正文为HTML格式的邮件(同时带附件)!!!
- 摄像头的网络传输问题(bmp压缩)
- 窗体的变化
- vararraycreate 函数
- 头疼的问题,请帮帮忙!!!UP有分
这是以前的一个解决的帖子,跟你参考一下1
有这样一个表:
人名 年 工资
a 2001 45544
a 2002 45455
a 2003 54566
b 2001 25455
b 2002 15455
b 2003 54566
怎么把2002年与2001的工资差额大于1000的记录查出来?? create table temp_calu(
e_name char(10),
wage_01 int,--01年工资
wage_02 int)--02年工资 将各个员工的人名,01年工资,02年工资放到这表里基可实现 delete from temp_calu -- 清除临时表原有记录***不可缺
insert into temp_calu(e_name) -- 为每个员工建立一条记录
select e_name from payment group by e_name --payment指你提供的这表 update temp_calu --为每个人插入01年工资
set wage_01 =
(select wage from payment
where payment.e_name = temp_calu.e_name and payment.year = 2001) update temp_calu --为每个人插入02年工资
set wage_02 =
(select wage from payment
where payment.e_name = temp_calu.e_name and payment.year = 2002) 求出结果:
select * from temp_calu
where abs(wage_02 - wage_01) > 1000
from dbo.TABLE1 a,dbo.TABLE1 b
where a.id<>b.id and a.[no]=b.[no]
union
select sum(qty) from dbo.TABLE1 group by no having count([no])=1在sql server 2000中通过
如果是sql server 2000,自定义函数是个很好的方法!