group by - How can I select a distinct combination of values across 3 or 4 columns in SQL Server -
I inherited a non-normalized table in SQL Server, with 15 columns of purchase records.
| Index | TransNo | Funds | Cost | City | ZIP | Bank | Risk_YesNo | ......
| 1 | 1 | Green | 34 NYC | ZIP | Sont |
| 2 | 12 | Party | 345.23 | NYC | ZIP | BOA_BS |
| 3 | 32 | Education | 43 | Boston | ZIP | BOA_BS |
| 4 | 53 | Books | 56 | Atl | ZIP | Citi |
| 5 | 422 | Groc | 12315 | Atl | ZIP | Pink |
-
I need to remove three specific combinations of columns and ignore others like index and transnation and put them in the same table (In planning for the next call, I want to generalize 2 - I have to include each specific value in my specific table
| fund | city | Bank |
| Green | NYC | Sont | // Green with City and Bank All different combinations of
| green | NYC | BOAS |
| ADWO | NYC | SONT | // All different combinations of ADU with city and bank.
| ADWO | NYC | BOA_BS |
Use Choose from
create specific
as well as enter
in the meritest, different fund, city, bank to get the specific record below. Choose from, blank, empty, blank, .... Mytable
E
For your comment below
1) How can I fill a default value for column Risk_YesNo = Y
< / Blockquote>Just include it in the
SELECT
query [see the example below]2) How do I get a random value value for example a column For [cost]
you can also include it in the
SELECT
query section. If you are using SQL Server 2008 and then you can still use the function to get it.
RAND ()
function returns afloat
type result, so if yourvalue
column if typeis an integer
, you must explicitly putCAST (RAND () as integer) [see the example below
with that question < / P>
Insert in mytable (fund, city, bank, risk_yah, cost, ....) Select a different fund,
Comments
Post a Comment