I have two tables
Stores=> id,zip_id,stores
Zips => id,zip_code,county,state
the column store in store table is comma separated values , how can i get all the stores states wise.
See if these threads can help,
separate comma separated values and store in table in sql server
Turning a Comma Separated string into individual rows
Related
I'm trying to get split comma-separated values into multiple rows.
here is my table and i have asin column with multiple comma separated value. i want to split asin value into multiple rows :-
i want record this type:-
My sample input has three columns with id, name and houses. My desired output is just two columns id , guid. where I did a transpose of all the row data to column based on column id. using select all statement. My question is when I do this I have comma separated values.
Is there a query I can use to to split these comma separated values and transpose
I have a table which contains columns with multiple values(comma separated).How to fetch data based on a single value from these columns.Using mysql as DBMS
I have 2 tables clients and grades where clients has a grade column with indices from 1 to 10. Those indices correspond to the ID's in the grades table (of course). Let's say a client has the indices 1,5,8 in the clients.grade column than I want to fetch * from those rows in the grades table.
My first approach was to use a grade field of type char(20) in the client table and fill it with indices separated by commas like 1,5,8 or others numbers. Then reading those values from one client from the client table I explode (PHP) the result and getting an array with 3 (or more) single values. Then in a following query I select all those rows in the grade table .
Now one question is wether to use a char field or an enumeration field and the other (general) question is how to make a simple, clever query for the entire task.
I did not code it yet. The grades table will have max. 10 rows, where as the client table has around 2.000 rows growing up to max. 5.000 rows. I hope I could describe my approach understandable.
Any suggestions are welcome
Split the grade column into a new table (client_grade?) containing clientId and grade, and have multiple records for each client. The grades for a client can then be retrieved using a JOIN from the clients to the clients_grade table on the client field
Each field in a table should hold a single piece of information and comma-separating values will cause you extra processing. Using a separate table will also aid you if you want to find out who got a particular grade etc
I am running the following REDSHIFT query on my table -
SELECT a,b,c
FROM table
WHERE a in( 303823703001,303823719403,303823675303);
I get the following error -
(null) types character varying and bigint cannot be matched
So i tried this -
SELECT a,b,c
FROM table
WHERE a::BIGINT in( 303823703001,303823719403,303823675303);
However this did not work because the column 'a' is VARCHAR type and contains values which may have alphabets.
So i tried this -
SELECT a,b,c
FROM table
WHERE a in( 303823703001::VARCHAR,303823719403::VARCHAR,303823675303::VARCHAR);
which worked!!
But my ISSUE is that i may have around 6000 comma separated numbers.
As a result the query will get very bloated.
I am looking to convert all the comma separated numbers to VARCHAR in an easier way.
Something like VARCHAR( 303823703001,303823719403,303823675303 )
The numbers that i get is from an excel sheet and these numbers are not stored in the db.