SQL查询语句的问题,有一定的难度,高手请进!!! 急~~~~~~~~在线等待

hanhanprogramer 2003-12-07 10:38:51
在视图VIEW_wholesale_export_memos中有如下SQL语句
SELECT SUM(quantity) AS quantity, drug_code, batch_no, wholesale_export_no
FROM wholesale_export_memos
GROUP BY drug_code, batch_no, wholesale_export_no

在视图VIEW_memos-strike中有如下SQL语句
SELECT b.export_no, a.strike_quantity, e.quantity, a.drug_code
FROM strike_export_memos a INNER JOIN
strike_export_main b ON a.strike_export_no = b.strike_export_no INNER JOIN
VIEW_wholesale_export_memos e ON b.export_no = e.wholesale_export_no AND
a.drug_code = e.drug_code AND a.batch_no = e.batch_no AND a.dispose_result <> '2'
最后需要一个简单的SQL语句来达到查询的目的
例如:select * from VIEW_memos-strike where a.strike_quantity <> e.quantity
请问高手:这样的东东能不能用一句SQL语句来实现查询的目的啊???如果能的话应该怎么写啊?如果能解决分不够的话可以加!!!
...全文
53 点赞 收藏 6
写回复
6 条回复
切换为时间正序
当前发帖距今超过3年,不再开放新的回复
发表回复
bflovesnow 2003-12-07
select * from VIEW_memos-strike v1 where not exists (select 1 from VIEW_wholesale_export_memos v2 where v1.strike_quantity=v2.quantity)
回复
bflovesnow 2003-12-07
select * from VIEW_memos-strike v1 where not exists (select 1 from VIEW_wholesale_export_memos v1 where v1.strike_quantity=v2.quantity)
回复
CrazyFor 2003-12-07
select * from VIEW_memos-strike where strike_quantity not in (select quantity from VIEW_wholesale_export_memos)
回复
wzh1215 2003-12-07
--或用已有的视图连也行!
SELECT b.export_no, a.strike_quantity, e.quantity, a.drug_code
FROM strike_export_memos a INNER JOIN
strike_export_main b ON a.strike_export_no = b.strike_export_no INNER JOIN
VIEW_wholesale_export_memos e ON b.export_no = e.wholesale_export_no
where a.drug_code = e.drug_code AND a.batch_no = e.batch_no
AND a.dispose_result <> '2'
回复
wzh1215 2003-12-07
SELECT b.export_no, a.strike_quantity, e.quantity, a.drug_code
FROM strike_export_memos a INNER JOIN
strike_export_main b ON a.strike_export_no = b.strike_export_no INNER JOIN
(
SELECT SUM(quantity) AS quantity, drug_code, batch_no, wholesale_export_no
FROM wholesale_export_memos
GROUP BY drug_code, batch_no, wholesale_export_no
) e
ON b.export_no = e.wholesale_export_no
where a.drug_code = e.drug_code AND a.batch_no = e.batch_no
AND a.dispose_result <> '2'
回复
azsoft 2003-12-07
SELECT b.export_no, a.strike_quantity, e.quantity, a.drug_code
FROM (SELECT SUM(quantity) AS quantity, drug_code, batch_no, wholesale_export_no
FROM wholesale_export_memos
GROUP BY drug_code, batch_no, wholesale_export_no)
a INNER JOIN
strike_export_main b ON a.strike_export_no = b.strike_export_no INNER JOIN
VIEW_wholesale_export_memos e ON b.export_no = e.wholesale_export_no AND
a.drug_code = e.drug_code AND a.batch_no = e.batch_no AND a.dispose_result <> '2'
回复
相关推荐
发帖
MS-SQL Server
创建于2007-09-28

3.3w+

社区成员

MS-SQL Server相关内容讨论专区
申请成为版主
帖子事件
创建了帖子
2003-12-07 10:38
社区公告
暂无公告