1. 订单创建时间最早的一笔订单订单号( )
select * from orders
where orderdate=(select min(orderdate) from orders)
1. 求货品金额最大的订单订单号( )
select top 1 orderid,sum(unitprice*quantity*(1-discount) ) from [order details] od
group by orderid
order by 2 desc
妙用group by ---分组属性要选好,
order by ---- 属性(asc和DESC)
1. 主键类型为组合主键的表有( )
----结果集为组合索引表名和组合索引名
select s.name,so.name from sysobjects s, -----表对象
(select id,name,parent_obj from sysobjects where xtype='PK') so, -----表中的索引对象
(select id from sysindexkeys ----查出一个数据库具有多个索引的表
group by id,indid
having count(*)>1)si
where so.parent_obj=si.id
and s.id=so.parent_obj
and s.xtype='U'
本文介绍了三种实用的SQL查询技巧:查找最早的订单记录、计算货品金额最高的订单及查询组合主键表。这些技巧帮助读者更好地理解和运用SQL,提高数据查询效率。
298

被折叠的 条评论
为什么被折叠?



