数据库技术:SQL Server简单实现数据的日报和月报功能实例讲述了sql server简单实现数据的日报和月报功能。分享给大家供大家参考,具体如下:
--320, sql server 日报 --查询2009-01-01当天客户a1,a2,a3的订单数量 select cust_name , convert(char(10), order_date, 120) order_date , sum(qty) qty from orders_big where 1=1 and cust_name in ('a1', 'a2', 'a3') and order_date >= '2009-01-01' and order_date<'2009-01-02' /*and order_date -- between...and相当于>=和<= between '2009-01-01' and '2009-01-02'*/ group by cust_name , convert(char(10), order_date, 120) order by 2, 1 --321. oracle 日报 --查询2009-01-01当天客户a1,a2,a3的订单数量 select cust_name , to_char(order_date, 'yyyy-mm-dd') order_date --方法一:转换成字符串类型 --, trunc(order_date) order_date --方法二:将时分秒信息截断 , sum(qty) qty from orders_big where 1=1 and cust_name in ('a1', 'a2', 'a3') and order_date >= date'2009-01-01' and order_date<date'2009-01-02' group by cust_name , to_char(order_date, 'yyyy-mm-dd')--方法一 --, trunc(order_date)--方法二 order by 2, 1 ------------------------------10.2------------------------------------ --326,sql server 月报 select cust_name , convert(char(7), order_date, 120) order_yrms , cast(convert(char(7), order_date, 120) + '-01' as datetime) order_date , sum(qty) qty from orders_big where 1=1 and cust_name in ('a1', 'a2', 'a3') and order_date >= '2009-01-01' and order_date<'2009-02-01' group by cust_name , convert(char(7), order_date, 120) order by 2, 1 --326, oracle select cust_name , to_char(order_date, 'yyyy-mm') order_yrms --方法1 --, trunc(order_date, 'mm') order_date--方法2 , sum(qty) qty from orders_big where 1=1 and cust_name in ('a1', 'a2', 'a3') and order_date >= date'2009-01-01' and order_date<date'2009-02-01' group by cust_name , to_char(order_date, 'yyyy-mm')--方法1 --, trunc(order_date, 'mm')--方法2 order by 2, 1
希望数据库技术:SQL Server简单实现数据的日报和月报功能所述对大家sql server数据库程序设计有所帮助。
需要了解更多数据库技术:SQL Server简单实现数据的日报和月报功能,都可以关注数据库技术分享栏目—计算机技术网(www.ctvol.com)!
本文来自网络收集,不代表计算机技术网立场,如涉及侵权请联系管理员删除。
ctvol管理联系方式QQ:251552304
本文章地址:https://www.ctvol.com/dtteaching/613544.html