mysql - unique and repeat column -


display unique , repeat column

sqlfiddle: http://sqlfiddle.com/#!9/97bac/1

select * `tbl_views_clicks` `idealid` =389 

result be:

|  iid | iuserid | idealid | icategoryid | isubcategoryid |    vtype | egaintype | ilocationid |              dtadded | edevicetype | |------|---------|---------|-------------|----------------|----------|-----------|-------------|----------------------|-------------| | 3410 |       1 |     389 |          79 |            135 | location |   instant |        1403 | 2017-08-21t11:26:51z |     android | | 3411 |       1 |     389 |          79 |            135 | location |   byclick |           0 | 2017-08-21t11:26:52z |     android | | 3412 |       1 |     389 |          79 |            135 |    gotit |   byclick |           0 | 2017-08-21t11:27:19z |     android | | 3413 |       1 |     389 |          79 |            135 |    gotit |   byclick |           0 | 2017-08-21t11:27:28z |     android | | 3414 |       1 |     389 |          79 |            135 |     |   byclick |           0 | 2017-08-21t11:27:32z |     android | | 3475 |     250 |     389 |          79 |            135 | location |   instant |        1403 | 2017-08-21t12:55:34z |     android | | 3476 |     250 |     389 |          79 |            135 | location |   byclick |           0 | 2017-08-21t12:55:36z |     android | | 3477 |     250 |     389 |          79 |            135 |    gotit |   byclick |           0 | 2017-08-21t12:56:39z |     android | | 3479 |     250 |     389 |          79 |            135 |  website |   byclick |           0 | 2017-08-21t13:04:30z |     android | | 3480 |     250 |     389 |          79 |            135 |  website |   byclick |           0 | 2017-08-21t13:04:54z |     android | | 3481 |     250 |     389 |          79 |            135 |  website |   byclick |           0 | 2017-08-21t13:05:06z |     android | | 3482 |     250 |     389 |          79 |            135 |    gotit |   byclick |           0 | 2017-08-21t13:05:16z |     android | | 3483 |     250 |     389 |          79 |            135 |     |   byclick |           0 | 2017-08-21t13:05:21z |     android | | 3484 |       1 |     389 |          79 |            135 |  website |   byclick |           0 | 2017-08-21t13:06:28z |     android | | 3485 |       1 |     389 |          79 |            135 |  website |   byclick |           0 | 2017-08-21t13:06:36z |     android | | 3486 |       1 |     389 |          79 |            135 |  website |   byclick |           0 | 2017-08-21t13:06:44z |     android | 

but want below:

-> if vtype gotit or first time customtype = 'unique' else customtype = 'repeat' -> if vtype website first time customtype = 'unique' else customtype = 'repeat' 

unique & repeat result:

|  iid | iuserid | idealid | icategoryid | isubcategoryid |    vtype | egaintype | ilocationid |              dtadded | edevicetype | customtype |------|---------|---------|-------------|----------------|----------|-----------|-------------|----------------------|-------------|------------- | 3410 |       1 |     389 |          79 |            135 | location |   instant |        1403 | 2017-08-21t11:26:51z |     android | unique | 3411 |       1 |     389 |          79 |            135 | location |   byclick |           0 | 2017-08-21t11:26:52z |     android | delete | 3412 |       1 |     389 |          79 |            135 |    gotit |   byclick |           0 | 2017-08-21t11:27:19z |     android | unique | 3413 |       1 |     389 |          79 |            135 |    gotit |   byclick |           0 | 2017-08-21t11:27:28z |     android | repeat | 3414 |       1 |     389 |          79 |            135 |     |   byclick |           0 | 2017-08-21t11:27:32z |     android | repeat | 3475 |     250 |     389 |          79 |            135 | location |   instant |        1403 | 2017-08-21t12:55:34z |     android | unique | 3476 |     250 |     389 |          79 |            135 | location |   byclick |           0 | 2017-08-21t12:55:36z |     android | delete | 3477 |     250 |     389 |          79 |            135 |    gotit |   byclick |           0 | 2017-08-21t12:56:39z |     android | unique | 3479 |     250 |     389 |          79 |            135 |  website |   byclick |           0 | 2017-08-21t13:04:30z |     android | unique | 3480 |     250 |     389 |          79 |            135 |  website |   byclick |           0 | 2017-08-21t13:04:54z |     android | repeat | 3481 |     250 |     389 |          79 |            135 |  website |   byclick |           0 | 2017-08-21t13:05:06z |     android | repeat | 3482 |     250 |     389 |          79 |            135 |    gotit |   byclick |           0 | 2017-08-21t13:05:16z |     android | repeat | 3483 |     250 |     389 |          79 |            135 |     |   byclick |           0 | 2017-08-21t13:05:21z |     android | repeat | 3484 |       1 |     389 |          79 |            135 |  website |   byclick |           0 | 2017-08-21t13:06:28z |     android | unique | 3485 |       1 |     389 |          79 |            135 |  website |   byclick |           0 | 2017-08-21t13:06:36z |     android | unique | 3486 |       1 |     389 |          79 |            135 |  website |   byclick |           0 | 2017-08-21t13:06:44z |     android | unique 

final result:

|  iid | iuserid | idealid | icategoryid | isubcategoryid |    vtype | egaintype | ilocationid |              dtadded | edevicetype | customtype |------|---------|---------|-------------|----------------|----------|-----------|-------------|----------------------|-------------|------------- | 3410 |       1 |     389 |          79 |            135 | location |   instant |        1403 | 2017-08-21t11:26:51z |     android | unique | 3411 |       1 |     389 |          79 |            135 | location |   byclick |           0 | 2017-08-21t11:26:52z |     android | delete // delete | 3412 |       1 |     389 |          79 |            135 |    gotit |   byclick |           0 | 2017-08-21t11:27:19z |     android | unique | 3413 |       1 |     389 |          79 |            135 |    gotit |   byclick |           0 | 2017-08-21t11:27:28z |     android | repeat | 3414 |       1 |     389 |          79 |            135 |     |   byclick |           0 | 2017-08-21t11:27:32z |     android | repeat // delete | 3475 |     250 |     389 |          79 |            135 | location |   instant |        1403 | 2017-08-21t12:55:34z |     android | unique | 3476 |     250 |     389 |          79 |            135 | location |   byclick |           0 | 2017-08-21t12:55:36z |     android | delete // delete | 3477 |     250 |     389 |          79 |            135 |    gotit |   byclick |           0 | 2017-08-21t12:56:39z |     android | unique | 3479 |     250 |     389 |          79 |            135 |  website |   byclick |           0 | 2017-08-21t13:04:30z |     android | unique | 3480 |     250 |     389 |          79 |            135 |  website |   byclick |           0 | 2017-08-21t13:04:54z |     android | repeat | 3481 |     250 |     389 |          79 |            135 |  website |   byclick |           0 | 2017-08-21t13:05:06z |     android | repeat // delete | 3482 |     250 |     389 |          79 |            135 |    gotit |   byclick |           0 | 2017-08-21t13:05:16z |     android | repeat | 3483 |     250 |     389 |          79 |            135 |     |   byclick |           0 | 2017-08-21t13:05:21z |     android | repeat // delete | 3484 |       1 |     389 |          79 |            135 |  website |   byclick |           0 | 2017-08-21t13:06:28z |     android | unique | 3485 |       1 |     389 |          79 |            135 |  website |   byclick |           0 | 2017-08-21t13:06:36z |     android | repeat | 3486 |       1 |     389 |          79 |            135 |  website |   byclick |           0 | 2017-08-21t13:06:44z |     android | repeat // delete 

so be:

|  iid | iuserid | idealid | icategoryid | isubcategoryid |    vtype | egaintype | ilocationid |              dtadded | edevicetype | customtype |------|---------|---------|-------------|----------------|----------|-----------|-------------|----------------------|-------------|------------- | 3410 |       1 |     389 |          79 |            135 | location |   instant |        1403 | 2017-08-21t11:26:51z |     android | unique | 3412 |       1 |     389 |          79 |            135 |    gotit |   byclick |           0 | 2017-08-21t11:27:19z |     android | unique | 3413 |       1 |     389 |          79 |            135 |    gotit |   byclick |           0 | 2017-08-21t11:27:28z |     android | repeat | 3475 |     250 |     389 |          79 |            135 | location |   instant |        1403 | 2017-08-21t12:55:34z |     android | unique | 3477 |     250 |     389 |          79 |            135 |    gotit |   byclick |           0 | 2017-08-21t12:56:39z |     android | unique | 3479 |     250 |     389 |          79 |            135 |  website |   byclick |           0 | 2017-08-21t13:04:30z |     android | unique | 3480 |     250 |     389 |          79 |            135 |  website |   byclick |           0 | 2017-08-21t13:04:54z |     android | repeat | 3482 |     250 |     389 |          79 |            135 |    gotit |   byclick |           0 | 2017-08-21t13:05:16z |     android | repeat | 3484 |       1 |     389 |          79 |            135 |  website |   byclick |           0 | 2017-08-21t13:06:28z |     android | unique | 3485 |       1 |     389 |          79 |            135 |  website |   byclick |           0 | 2017-08-21t13:06:36z |     android | repeat 

in short, second entry must defined repeat in customtype column

how can done?

select distinct iuserid, idealid, icategoryid, isubcategoryid, vtype, egaintype, ilocationid, dtadded, edevicetype,customtype   (select *, case               when instr(@var_column, vtype) > 0 'repeat'               else 'unique'           end customtype, @var_column :=concat(@var_column,case when vtype ='gotit' or 'back' 'gotit,back' else vtype end)    `tbl_views_clicks`,      (select @var_column :='')z    group case                 when vtype in ('gotit','back') 1                 else vtype             end,             customtype    order dtadded)z 

Comments

Popular posts from this blog

ubuntu - PHP script to find files of certain extensions in a directory, returns populated array when run in browser, but empty array when run from terminal -

php - How can i create a user dashboard -

javascript - How to detect toggling of the fullscreen-toolbar in jQuery Mobile? -