display duplicate record
I have a table called problemTBL, which contains the fields below
problem_id Autoincrement,Pk
passenger_id, accept duplicate values
problem_name, problem description
These are sample records:
Problem_id passenger_id problem_name
1 22 NO Air condition
2 22 Dirty Seats
3 24 Driver Not helped
4 22 Old Age Car
5 23 Old Age Driver
6 开发者_运维知识库 22 Very speed driving
Now I want to retrieve a record like
["NO Air condition","Dirty Seats","Old Age Car","Very speed driving","","","","","","","","","","",""] passenger_id 22
["Driver Not helped","","","","","","","","","","","","","",""] passenger_id 24
OR
passenger_id problem_name
22 NO Air condition |=| Dirty Seats |=| Very speed driving |=|Old Age Car
24 Driver Not helped
23 Old Age Driver
Is it possible with a query?
Hi the thing , am doing migration ,
at present i kept all the problem in each now, now i am doing migration , i want to keep all problem for the particular customer into one single row,
That is one customer can raise compliant upto 15 only(For complaint we have seprate form , there we asking some questions, they just tick and submit..)
So we have decided clearly that is only 15 problem ,
So one row for one customer,
That is now latest compliant form have 15 complaint , if they selected , then that problem will check else empty val will be insert ,
While submiting the form am just post all values into json_encoded and then am insert this json into table...
Got it my point...
For future complaint i done program well,
But past compliants i want to migrate , so that i posted question here,.,,
You may use group_concat() to aggregate text fields from multiple rows.
SELECT
`passenger_id`,
GROUP_CONCAT(`problem_name` SEPARATOR ' |=| ')
FROM
`problemTBL`
GROUP BY
`passenger_id`
Additionally you may wish to increase group_concat_max_len variable.
Before SELECT query: SET SESSION group_concat_max_len = max_bytes
read about cross-tabulations (aka pivot tables) here:
http://onlamp.com/pub/a/onlamp/2003/12/04/crosstabs.html
精彩评论