sql server - sql get name of day and count it -


I am from Indonesia, I have a problem creating reports with SQL Server. I have a transaction table,

Date | Trx_ID | Member_id | Invt_id | Branch_id 01-01-2013 | Tr001 | 0002 | Invt002 | Br001 01-01-2013 | Tr001 | 0002 | Invt003 | Br001 01-01-2013 | Tr001 | 0002 | Invt004 | Br001 01-03-2013 | Tr002 | 0001 | Invt001 | Br001 01-03-2013 | Tr002 | 0001 | Invt003 | Br001 01-04-2013 | Tr003 | 0003 | Invt002 | Br001 01-04-2013 | Tr003 | 0003 | Invt004 | Br001 01-05-2013 | Tr004 | 0002 | Invt005 | Br001 01-05-2013 | Tr004 | 0002 | Invt006 | Br001 01-05-2013 | Tr005 | 0005 | Invt004 | Br001 01-05-2013 | Tr005 | 0005 | Invt005 | Br001 01-05-2013 | Tr005 | 0005 | Invt006 | Br001 01-06-2013 | Tr006 | 0001 | Invt001 | Br001 01-06-2013 | Tr006 | 0001 | Invt002 | Br001

And I have to make such a report

 Branch_id | Workdays | Weekend | Weekly day | Weekend | BRICS | 2 | 1 | 2 

The member_id has its mean group and if the weekend transaction is counted on weekdays, if the member taking the transaction on weekdays is counted on weekends, but if the member week Are trading in days and at the end of the week it is counted on the dates of the week. Weekends are: Saturday and Sunday are the working days: Monday, Tuesday, Wednesday, Thursday and Friday, weekday_wecend if member is doing more than 1 transaction and doing weekends and weekdays

The wrong question is when I try

 Select Max (Branch_ID), Count (different trx_id) , Zodiac (in case when the date (dw, date) is 'weekend' In the form, when ('Saturday', 'Sunday'), 'Weekend', Zodiac (in case when Dinankan (dw, date), 'Weekend' ('Monday', 'Tuesday', 'Wednesday', 'Thursday' 'Friday', 'Saturday', 'Sunday') and then the end of 1 second) in the form of 'WEEKZE_WEEKEND' from the transaction where the branch ID = '14067' and convert (four (6), date, 112) = 201301 'Group_id by group 

not resulted group trx_id and member_id

 Branch_id | Weekday | Weekend | Weekday | 7 | 7 | 0 

I'm sorry And my English is poor, then help me create a report

OK, I can not understand What are you doing based on the count of days of the week but there are questions to check the total transactions on weekends or weekends

  SELECT branch_id, SUM (case, when DATEPART (Dw, date]) no (1,7) again 1 ELSE 0 END) as the days of the week, SUM (case when DATEPART (dw, [date]) IN (1,7) THEN 1 ELSE 0 END) Weekend In the form of the branch, the branch_id  

the DATEPART () function concludes the day of the week when it is passed to dw is returned value from 1 to 7, Saturday is 7, Sunday is 1


Comments

Popular posts from this blog

import - Python ImportError: No module named wmi -

Editing Python Class in Shell and SQLAlchemy -

c# - MySQL Parameterized Select Query joining tables issue -