Can any one help me out here with a syntax to split the data in a row and see if the splitted data is appearing again the count of that splitted info should be obtained.
If you see the below input table. C1 has a data like ABC, ACD, BCE etc.. I want to split that and have a count for each specific data and also the total count.
Help is appreciated in MYSQL
Query i tried in SQL server: As a new bibe i to MYSQL i was able to get data as whole but i was unable to split. For Example, i know select C1 from inputtable. But i unable to get idea to split the data that a row have in a specified column.
Diagramatical Explanation:
Input Table:
C1
----------
ABC
ACD
BCE
NULL
A
Output Table:
Column1 Count TotalCount
------------------------------------------------------
A 3 4
B 2 4
C 3 4
D 1 4
E 1 4
Splitting data into an arbitrary number of columns would require stored procedures or some similar uglyness. Splitting into ten columns is possible, but turning these columns into rows so you can aggregate them would again require ugly code. All of this indicates that your schema probably is in violation with the first normal form: you’re storing multiple values in a single table “cell”. Can you modify the schema, or do you have to use that one?
If you have to use that one, here is some ugly code to get you startet. It produces the requested output on your sample input, as tested on SQLFiddle.
Note that I definitely would not advise you to write things this way. Use a proper database schema instead, where you don’t have to repeat lines a fixed number of times. And also consider using a separate query to fetch the total, as repeating that for every row of the result appears rather pointless.