afaquecena Posted September 13, 2017 Share Posted September 13, 2017 Hi Friends,I am stucked in a situation where with my SQL query I am getting an output such as-:FnameLnameEvent1Event2abcxyzNoYesabcxyzYesNoSo this is the output which iam getting with my SQL query and I want my output to be of single row so that the end user have a glance at the report and can easily guess which are the event that guy has attended.FnameLnameEvent1Event2abcxyzYesYes Link to comment Share on other sites More sharing options...
szaharia Posted September 13, 2017 Share Posted September 13, 2017 You should modify the query, in order to get a single row per each name. For instance:select Fname, Lname, max(Event1) as evt1, max(Event2) as evt2 from my_table group by Fname, Lname Link to comment Share on other sites More sharing options...
anji.viper Posted November 22, 2017 Share Posted November 22, 2017 You can try with this query.. It may be a bit long but since your data is simple, it should suit your needs well. It basically checks whether there's at least 1 Yes in each event then outputs Yes in the same row for the Fname and Lname in the list.select x.Fname, x.Lname, (case when x.evt1 > 0 then 'Yes' else 'No' end) as event1, (case when x.evt2 > 0 then 'Yes' else 'No' end) as event2from (select Fname, Lname, count(case when Event1 ='Yes' then 1 else 0 end) as evt1, count(case when Event2 ='Yes' then 1 else 0 end) as evt2from table_namegroup by Fname, Lname) as x[/code] Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now