vengelus82
Technical User
Dear all,
this is my following problem:
28035,"104"
28035,"31"
28035,"39"
28035,"75"
28035,"2"
28035,"86"
28035,"44"
28035,"84"
28035,"98"
476,"1"
476,"76"
476,"40"
476,"31"
476,"102"
476,"93"
476,"53"
476,"83"
476,"96"
6697,"76"
6697,"1"
6697,"41"
6697,"32"
6697,"102"
6697,"94"
6697,"83"
6697,"96"
the first column are my users and the second column is the attribute they have in their profile. This profile is voluntarily added by users.
1 and 2 represent gender attribute, as you can see, these attributes are recorded in the table in different order
I have the following mysql query to extract them and this is the following what I get
Query
DROP TABLE IF EXISTS temp_gender;
CREATE TABLE temp_gender(
select
user_profiles.user_id,
(CASE WHEN user_profiles.profile_id = 1 THEN 1 WHEN user_profiles.profile_id = 2 THEN 2 ELSE user_profiles.profile_id = 0 END) AS 'gender'
FROM user_profiles);
28035,"0"
28035,"0"
28035,"0"
28035,"0"
28035,"2"
28035,"0"
28035,"0"
28035,"0"
28035,"0"
476,"1"
476,"0"
476,"0"
476,"0"
476,"0"
476,"0"
476,"0"
476,"0"
476,"0"
6697,"0"
6697,"1"
6697,"0"
6697,"0"
6697,"0"
6697,"0"
6697,"0"
6697,"0"
2397,"1"
2397,"0"
2397,"0"
2397,"0"
2397,"0"
2397,"0"
2397,"0"
2397,"0"
2397,"0"
if I would use
DROP TABLE IF EXISTS temp_gender;
CREATE TABLE temp_gender(
select
DISTINCT user_profiles.user_id,
(CASE WHEN user_profiles.profile_id = 1 THEN 1 WHEN user_profiles.profile_id = 2 THEN 2 ELSE user_profiles.profile_id = 0 END) AS 'gender'
FROM user_profiles
Then I get
"28035","0"
"476","0"
"6697","0"
"2397","0"
if I use
DROP TABLE IF EXISTS temp_gender;
CREATE TABLE temp_gender(
select
user_profiles.user_id,
(CASE WHEN user_profiles.profile_id = 1 THEN 1 WHEN user_profiles.profile_id = 2 THEN 2 ELSE 0 END) AS 'gender'
FROM user_profiles
GROUP BY user_profiles.user_id);
Then I get
"28035","0"
"476","1"
"6697","0"
"2397","1"
And finally when I use
DROP TABLE IF EXISTS temp_gender;
CREATE TABLE temp_gender(
select
distinct user_profiles.user_id,
(CASE WHEN user_profiles.profile_id = 1 THEN 1 WHEN user_profiles.profile_id = 2 THEN 2 ELSE 0 END) AS 'gender'
FROM user_profiles);
I get
"28035","0"
"28035","2"
"476","1"
"476","0"
"6697","0"
"6697","1"
"2397","1"
"2397","0"
the question is
How would I need to change my statement to get
"28035","2"
"476","1"
"6697","1"
"2397","1"
"13397","0"(this user did not fill in his/her gender)
this is my following problem:
28035,"104"
28035,"31"
28035,"39"
28035,"75"
28035,"2"
28035,"86"
28035,"44"
28035,"84"
28035,"98"
476,"1"
476,"76"
476,"40"
476,"31"
476,"102"
476,"93"
476,"53"
476,"83"
476,"96"
6697,"76"
6697,"1"
6697,"41"
6697,"32"
6697,"102"
6697,"94"
6697,"83"
6697,"96"
the first column are my users and the second column is the attribute they have in their profile. This profile is voluntarily added by users.
1 and 2 represent gender attribute, as you can see, these attributes are recorded in the table in different order
I have the following mysql query to extract them and this is the following what I get
Query
DROP TABLE IF EXISTS temp_gender;
CREATE TABLE temp_gender(
select
user_profiles.user_id,
(CASE WHEN user_profiles.profile_id = 1 THEN 1 WHEN user_profiles.profile_id = 2 THEN 2 ELSE user_profiles.profile_id = 0 END) AS 'gender'
FROM user_profiles);
28035,"0"
28035,"0"
28035,"0"
28035,"0"
28035,"2"
28035,"0"
28035,"0"
28035,"0"
28035,"0"
476,"1"
476,"0"
476,"0"
476,"0"
476,"0"
476,"0"
476,"0"
476,"0"
476,"0"
6697,"0"
6697,"1"
6697,"0"
6697,"0"
6697,"0"
6697,"0"
6697,"0"
6697,"0"
2397,"1"
2397,"0"
2397,"0"
2397,"0"
2397,"0"
2397,"0"
2397,"0"
2397,"0"
2397,"0"
if I would use
DROP TABLE IF EXISTS temp_gender;
CREATE TABLE temp_gender(
select
DISTINCT user_profiles.user_id,
(CASE WHEN user_profiles.profile_id = 1 THEN 1 WHEN user_profiles.profile_id = 2 THEN 2 ELSE user_profiles.profile_id = 0 END) AS 'gender'
FROM user_profiles
Then I get
"28035","0"
"476","0"
"6697","0"
"2397","0"
if I use
DROP TABLE IF EXISTS temp_gender;
CREATE TABLE temp_gender(
select
user_profiles.user_id,
(CASE WHEN user_profiles.profile_id = 1 THEN 1 WHEN user_profiles.profile_id = 2 THEN 2 ELSE 0 END) AS 'gender'
FROM user_profiles
GROUP BY user_profiles.user_id);
Then I get
"28035","0"
"476","1"
"6697","0"
"2397","1"
And finally when I use
DROP TABLE IF EXISTS temp_gender;
CREATE TABLE temp_gender(
select
distinct user_profiles.user_id,
(CASE WHEN user_profiles.profile_id = 1 THEN 1 WHEN user_profiles.profile_id = 2 THEN 2 ELSE 0 END) AS 'gender'
FROM user_profiles);
I get
"28035","0"
"28035","2"
"476","1"
"476","0"
"6697","0"
"6697","1"
"2397","1"
"2397","0"
the question is
How would I need to change my statement to get
"28035","2"
"476","1"
"6697","1"
"2397","1"
"13397","0"(this user did not fill in his/her gender)