这样可以满足你的要求. (select * from sales where productid in (select distinct productid from sales where kaiguan=1)) union (select * from sales where id in (select min(id) from sales where (kaiguan is null) group by productid))
sql="select A.* from Sales A inner join (select BigTypeID,ProductID,min(ID) as ID from Sales group by BigTypeID,ProductID) B on A.ID=B.ID where A.BigtypeID='"&BigTypeID&"'"jsddj 能不能帮我在现有的语句上面改进?或者帮我用我这样的格式写出来?
呵呵,那就改成这样吧.再试试. (select * from sales where kaiguan is null) union (select * from sales where id in (select min(id) from sales where (kaiguan=1) group by productid))
郁闷,我在查询分析器里面测试可以的,但应用到程序里面就行了 Sql="(select * from sales where kaiguan is null) union (select * from sales where id in (select min(id) from sales where (kaiguan=1) group by productid))"
(select * from sales where productid in (select distinct productid from sales where kaiguan=1)) union (select * from sales where id in (select min(id) from sales where (kaiguan is null) group by productid))
sql="select A.* from Sales A inner join (select BigTypeID,ProductID,min(ID) as ID from Sales group by BigTypeID,ProductID) B on A.ID=B.ID where A.BigtypeID='"&BigTypeID&"'"jsddj 能不能帮我在现有的语句上面改进?或者帮我用我这样的格式写出来?
而我想要的是不论productid相同且kaiguai值为1时,不论有多少条,只显示一条就够了
from (
select A.*
from Sales A
inner join
(select BigTypeID,ProductID,min(ID) as ID
from Sales
group by BigTypeID,ProductID) B
on A.ID=B.ID
where a.kaiguan is null
union
select * from sales where kaiguan = '1') c
where BigtypeID=@BigTypeID
(select * from sales where kaiguan is null) union (select * from sales where id in (select min(id) from sales where (kaiguan=1) group by productid))
Sql="(select * from sales where kaiguan is null) union (select * from sales where id in (select min(id) from sales where (kaiguan=1) group by productid))"