sql语句问题?!请帮忙!
select * from dbo_Fc_Products where TypeID in (select min(TypeID) from dbo_Fc_Products) and STypeID = 5 order by PID desc
看看这么写可以么
------解决方案--------------------没什么不可以吧
------解决方案--------------------整理一下:
select *
from dbo_Fc_Products
where TypeID in (select min(TypeID) from dbo_Fc_Products)
and STypeID = 5
order by PID desc
------------------------
select min(TypeID) from dbo_Fc_Products
可以用 group by 约束。
------解决方案--------------------完全可以~~
------解决方案--------------------SELECT * FROM [dbo_Fc_Products] WHERE TypeID = (SELECT TOP 1 TypeID FROM [dbo_Fc_Products ] ORDER BY TypeID ASC) and STypeID = 5 order by PID desc
这样写效率好像高一点,如果只取一个值的,最好不要用 IN
------解决方案--------------------declare @TypeID int;
SELECT @TypeID= min(TypeID) from dbo_Fc_Products;
select * from dbo_Fc_Products where TypeID =@TypeID and STypeID = 5 order by PID desc;
这样也可以的,哈哈。