Daily income and expenditure

Source: Internet
Author: User

If object_id ('[TB]') is not null drop table [TB]
Go
Create Table [TB] (Name: varchar (10), amount: int, sign: varchar (2), date: varchar (30) -- Revenue 1 expenditure: 2
Insert [TB]
Select 'A', 100, '1', '2017-11-23 'Union all
Select 'B', 150, '2', '2017-11-22 'Union all
Select 'C', 190, '1', '2017-11-23 'Union all
Select 'D', 110, '2', '2017-11-23 'Union all
Select 'E', 145, '1', '2017-11-24'

Select * from TB

Select
Convert (varchar (10), date, 120) as date,
Sum (case indicates when 1 then amount else 0 end) as income,
Sum (case indicates when 2 then amount else 0 end) as expenditure
From
TB
Group
Convert (varchar (10), date, 120)

/*

Name amount flag date
-------------------------------------------------------
A 100 1
B 150 2
C 190 1
D 110 2
E 145 1

Date Income Expenditure
--------------------------------
2009-11-22 0 150
2009-11-23 290 110
145 0

*/

 

 

select batchid,max(message),min(SendTime), sum(case result1 when 0 then 1 else 0 end) as TotalSub, sum(case result2 when 0 then 1 else 0 end) as SuccSubNumber, sum(case result3 when 0 then 1 else 0 end) as AbsoluteSuccNumberfrom Send WHERE  CompanyID=1group by  batchid order by batchid desc

 

  

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.