sql server - SQL: Add a column and classify into categories -


I have a table that contains transaction_id as the primary code and in this customer_id < / Code> which is a foreign key

Now a column is type which has two values: 'card' and 'cash' .

Now some customers have used both methods for payment I want to add a new column and classify customers as "only cards" as "only cash" and "both"

  Transaction ID Customer ID Type 1 100 Card 2 101 Cash 3 102 Card 4 103 Cash 5 101 Card  

So in this table I have a new I want column 'type of payment' which classifies customer 101 as both Because he has used both methods of payment.

Instead of adding a column to the table, if you analyze the payment methods you want to do , Then it may be better to do something like this:

  Select the difference table 1. [Customer id], t1 * Apply 1 table 1 cross from (select SUM (in case [type] = 'cash' then 1 ELSE 0 END) AS cash, SM (case when [type] = 'card' then 1 ELS 0nd Table 1 T virus T. [customer ID] = table 1. [customer ID]) T1  

gives you results like this:

  Customer ID cache card 100 0 1 101 1 1 102 0 1 103 1 0  

Comments

Popular posts from this blog

HTML/CSS - Automatically set height width from background image? -

php - Mysql Show Process - Sleep Commands and what to do -

c - What is the address of buf (the local variable in the main function)? -