sql查询(1)
时间:2011-03-21 来源:天璇翼
--选择所有字段
SELECT * FROM products
go
--选择部分字段
SELECT CategoryName,Description FROM Categories
go
--不显示重复字段DISTINCT
SELECT DISTINCT City as 城市 FROM Customers
go
--排序[ASC|DEC]
SELECT * FROM customers ORDER BY ContactName desc
--分组GROUP BY
--单列分组
SELECT CategoryID FROM products GROUP BY CategoryID
--多列分组
SELECT CategoryID,UnitPrice FROM products GROUP BY CategoryID,UnitPrice
go
--使用聚合函数进行查询
SELECT sum(UnitPrice) as 每类总和 ,CategoryID FROM products GROUP BY CategoryID
go
相关阅读 更多 +