The select * from table1 data below
The KEY value
1 blue
1 red
2 large.
2 small
61 fine
61 ordinary article
After cross combinations can display the
Field 1 2
1 blue/large/boutique
2 blue/large/ordinary article
Three blue/small/boutique
4 blue/small/ordinary article
Five red/large/boutique
6 red/large/ordinary article
7 red/small/boutique
8 red/small/ordinary article
I just want to ask dynamic statement how to write, static statements I've written out, is that the data is how to realize dynamic, thank you, wait,
CodePudding user response:
Nobody CSDN on weekend?CodePudding user response:
SELECT @ R:=@ R + 1 ` KEY `, t.v alue the FROM (
SELECT @ R:=0, CONCAT_WS ('/', t1. Value, t2. Value, t3. Value) value FROM (
SELECT '1' ` KEY `, 'blue' VALUE FROM DUAL UNION ALL
SELECT '1' ` KEY `, 'red' VALUE FROM DUAL UNION ALL
SELECT '2' ` KEY `, 'large' VALUE FROM DUAL UNION ALL
SELECT '2' ` KEY `, 'small' VALUE FROM DUAL UNION ALL
SELECT '61' ` KEY `, 'boutique' VALUE FROM DUAL UNION ALL
SELECT '61' ` KEY `, 'common goods' VALUE FROM DUAL) t1
The JOIN (
SELECT '1' ` KEY `, 'blue' VALUE FROM DUAL UNION ALL
SELECT '1' ` KEY `, 'red' VALUE FROM DUAL UNION ALL
SELECT '2' ` KEY `, 'large' VALUE FROM DUAL UNION ALL
SELECT '2' ` KEY `, 'small' VALUE FROM DUAL UNION ALL
SELECT '61' ` KEY `, 'boutique' VALUE FROM DUAL UNION ALL
SELECT '61' ` KEY `, 'common goods' VALUE FROM DUAL) t2 ON 1=1
The JOIN (
SELECT '1' ` KEY `, 'blue' VALUE FROM DUAL UNION ALL
SELECT '1' ` KEY `, 'red' VALUE FROM DUAL UNION ALL
SELECT '2' ` KEY `, 'large' VALUE FROM DUAL UNION ALL
SELECT '2' ` KEY `, 'small' VALUE FROM DUAL UNION ALL
SELECT '61' ` KEY `, 'boutique' VALUE FROM DUAL UNION ALL
SELECT '61' ` KEY `, 'common goods' VALUE FROM DUAL) t3 ON 1=1
WHERE a t1. ` KEY `='1' AND t2. ` KEY `='2' AND t3. ` KEY ` t='61');
CodePudding user response:
My data will be change, add it, add a black, how to make this static doesn't make any senseCodePudding user response:
I don't have your list, so he had to write a temporary table, you can add several hundred models, add tens of billions of color is no problem,As long as your group is 3 groups there will be no problem,
Your table name is table1, for example, my that temporary table, buffer your table name table1,
My temporary table:
(
SELECT '1' ` KEY `, 'blue' VALUE FROM DUAL UNION ALL
SELECT '1' ` KEY `, 'red' VALUE FROM DUAL UNION ALL
SELECT '2' ` KEY `, 'large' VALUE FROM DUAL UNION ALL
SELECT '2' ` KEY `, 'small' VALUE FROM DUAL UNION ALL
SELECT '61' ` KEY `, 'boutique' VALUE FROM DUAL UNION ALL
SELECT '61' ` KEY `, 'common goods' VALUE FROM DUAL)
CodePudding user response:
My group is change, like taobao clothing size, there are large and small, size, color, is likely to be male, female, is change,CodePudding user response: