将表1(xh.dbf)通过SQL得到表2,如:
表1:
xh | custor | zxs | hh | pm | qty | size | cm | zl |
A171 | ANDY | 1 | A00787 | T恤 | 8 | 80*50*60 | CHINA | 8.48 |
A171 | ANDY | B00555 | T恤 | 30 | 0 | CHINA | 0.00 | |
A171 | ANDY | B00557 | T恤 | 30 | 0 | CHINA | 0.00 | |
A171 | ANDY | A00772 | T恤 | 50 | 0 | CHINA | 0.00 | |
A171 | ANDY | A00773 | T恤 | 50 | 0 | CHINA | 0.00 | |
K043 | hero | 1 | * | T恤 | 100 | 53*33*76 | CHINA | 4.69 |
K043 | hero | / | T恤 | 90 | 0 | CHINA | 0.00 | |
A152* | 爱 | 1 | 891 | T恤 | 60 | 53*33*28 | CHINA* | 1.73 |
A153 | 爱 | 1 | * | T恤 | 20 | 53*33*20 | CHINA | 1.24 |
A153 | 爱 | 915 | T恤 | 20 | 0 | CHINA | 0.00 | |
K042 | 冰冻 | 1 | 312 | T恤 | 45 | 53*33*65 | CHINA | 4.01 |
K042 | 冰冻 | 313 | T恤 | 80 | 0 | CHINA | 0.00 | |
K042 | 冰冻 | / | T恤 | 50 | 0 | CHINA | 0.00 | |
K042 | 冰冻 | * | T恤 | 9 | 0 | CHINA | 0.00 | |
A162 | 脖子 | 1 | 3336 | T恤 | 146 | 53*33*62 | CHINA | 3.83 |
A181 | 脖子 | 1 | 3628 | T恤 | 145 | 53*33*76 | CHINA | 4.69 |
A181 | 脖子 | 3340 | T恤 | 10 | 0 | CHINA | 0.00 | |
A182 | 脖子 | 1 | 3340 | T恤 | 140 | 53*33*76 | CHINA | 4.69 |
A182 | 脖子 | 3328 | T恤 | 40 | 0 | CHINA | 0.00 | |
A183 | 脖子 | 1 | 3328 | T恤 | 104 | 53*33*76 | CHINA | 4.69 |
A183 | 脖子 | 3375 | T恤 | 60 | 0 | CHINA | 0.00 | |
A184 | 脖子 | 1 | 3375 | T恤 | 87 | 53*33*76 | CHINA | 4.69 |
A184 | 脖子 | 3365 | T恤 | 70 | 0 | CHINA | 0.00 | |
A185 | 脖子 | 1 | 3365 | T恤 | 73 | 53*33*36 | CHINA | 2.22 |
B085 | 脖子 | 1 | 3733 | T恤 | 147 | 53*33*76 | HK | 4.69 |
B085 | 脖子 | 3734 | T恤 | 10 | 0 | HK | 0.00 | |
B086 | 脖子 | 1 | 3734 | T恤 | 140 | 53*33*76 | HK | 4.69 |
B086 | 脖子 | 3307 | T恤 | 20 | 0 | HK | 0.00 | |
B087 | 脖子 | 1 | 3307 | T恤 | 128 | 53*33*56 | HK | 3.46 |
B084 | 不不 | 1 | 07-1093 | T恤 | 216 | 80*50*60 | HK | 8.48 |
B084 | 不不 | 07-1093* | T恤 | 128 | 0 | HK | 0.00 | |
B084 | 不不 | 07-1093+ | T恤 | 109 | 0 | HK | 0.00 | |
A176 | 淡淡 | 1 | 30266 | T恤 | 28 | 80*50*60 | CHINA | 8.48 |
A176 | 淡淡 | 30219 | T恤 | 48 | 0 | CHINA | 0.00 | |
A176 | 淡淡 | 30374 | T恤 | 108 | 0 | CHINA | 0.00 | |
A176 | 淡淡 | 31400 | T恤 | 72 | 0 | CHINA | 0.00 | |
A176 | 淡淡 | 30586 | T恤 | 102 | 0 | CHINA | 0.00 | |
A177 | 淡淡 | 1 | 30563 | T恤 | 108 | 80*50*60 | CHINA | 8.48 |
A177 | 淡淡 | 30192 | T恤 | 60 | 0 | CHINA | 0.00 | |
A177 | 淡淡 | 30465 | T恤 | 28 | 0 | CHINA | 0.00 | |
A177 | 淡淡 | 30857 | T恤 | 72 | 0 | CHINA | 0.00 | |
A177 | 淡淡 | 31094 | T恤 | 48 | 0 | CHINA | 0.00 | |
A178 | 淡淡 | 1 | 30560 | T恤 | 108 | 80*50*60 | CHINA | 8.48 |
A178 | 淡淡 | 30562 | T恤 | 108 | 0 | CHINA | 0.00 | |
A178 | 淡淡 | 31149 | T恤 | 72 | 0 | CHINA | 0.00 | |
A178 | 淡淡 | 31198 | T恤 | 48 | 0 | CHINA | 0.00 | |
A178 | 淡淡 | 30760 | T恤 | 36 | 0 | CHINA | 0.00 | |
A173 | 发 | 1 | 208 | T恤 | 18 | 53*33*17 | CHINA | 1.05 |
K036 | 发财 | 1 | 97547 | T恤 | 20 | 65*38*67 | CHINA | 5.84 |
K036 | 发财 | 96572 | T恤 | 60 | 0 | CHINA | 0.00 | |
K037 | 发财 | 1 | 96572 | T恤 | 10 | 65*38*67 | CHINA | 5.84 |
K037 | 发财 | 97550 | T恤 | 70 | 0 | CHINA | 0.00 | |
K038 | 发财 | 1 | 9002 | T恤 | 50 | 65*38*67 | CHINA | 5.84 |
K038 | 发财 | 9005 | T恤 | 26 | 0 | CHINA | 0.00 | |
K038 | 发财 | 1227 | T恤 | 26 | 0 | CHINA | 0.00 | |
K038 | 发财 | 9872 | T恤 | 20 | 0 | CHINA | 0.00 | |
K038 | 发财 | 9883 | T恤 | 20 | 0 | CHINA | 0.00 | |
K038 | 发财 | 332 | T恤 | 30 | 0 | CHINA | 0.00 | |
K038 | 发财 | 331 | T恤 | 40 | 0 | CHINA | 0.00 | |
K041 | 发财 | 1 | / | T恤 | 60 | 53*33*62 | CHINA | 3.83 |
K041 | 发财 | 604 | T恤 | 20 | 0 | CHINA | 0.00 | |
K041 | 发财 | 602 | T恤 | 30 | 0 | CHINA | 0.00 | |
K048 | 发财 | 1 | B001 | T恤 | 70 | 65*38*67 | CHINA | 5.84 |
K40* | 发财 | 1 | 5628-1 | T恤 | 100 | 80*50*60 | CHINA* | 8.48 |
A163 | 方方 | 1 | 02 | T恤 | 16 | 53*33*68 | CHINA | 4.20 |
A163 | 方方 | 0731 | T恤 | 35 | 0 | CHINA | 0.00 | |
A163 | 方方 | 8028 | T恤 | 30 | 0 | CHINA | 0.00 | |
A163 | 方方 | 915 | T恤 | 35 | 0 | CHINA | 0.00 | |
A163 | 方方 | 921 | T恤 | 24 | 0 | CHINA | 0.00 | |
A163 | 方方 | 908 | T恤 | 10 | 0 | CHINA | 0.00 | |
B090 | 方方 | 1 | 509 | T恤 | 25 | 53*33*21 | HK | 1.30 |
A166 | 工人 | 1 | \ | T恤 | 190 | 53*33*76 | CHINA | 4.69 |
A166 | 工人 | * | T恤 | 130 | 0 | CHINA | 0.00 | |
A167 | 工人 | 1 | * | T恤 | 70 | 53*33*76 | CHINA | 4.69 |
A167 | 工人 | \ | T恤 | 10 | 0 | CHINA | 0.00 | |
A167 | 工人 | - | T恤 | 150 | 0 | CHINA | 0.00 | |
A168 | 工人 | 1 | - | T恤 | 49 | 53*33*76 | CHINA | 4.69 |
A168 | 工人 | | | T恤 | 190 | 0 | CHINA | 0.00 | |
A169 | 工人 | 1 | | | T恤 | 10 | 70*50*50 | CHINA | 6.18 |
A169 | 工人 | + | T恤 | 90 | 0 | CHINA | 0.00 | |
A169 | 工人 | | | T恤 | 200 | 0 | CHINA | 0.00 | |
A170 | 工人 | 1 | / | T恤 | 200 | 53*33*76 | CHINA | 4.69 |
D045 | 好好 | 1 | / | T恤 | 251 | 80*50*60 | HK | 8.48 |
D046 | 好好 | 1 | * | T恤 | 151 | 80*50*60 | HK | 8.48 |
D046 | 好好 | + | T恤 | 124 | 0 | HK | 0.00 | |
D047 | 好好 | 1 | + | T恤 | 210 | 65*38*67 | HK | 5.84 |
D048 | 好好 | 1 | * | T恤 | 185 | 80*50*60 | HK | 8.48 |
D049 | 好好 | 1 | - | T恤 | 68 | 65*38*60 | HK | 5.23 |
D049 | 好好 | + | T恤 | 65 | 0 | HK | 0.00 | |
D049 | 好好 | * | T恤 | 21 | 0 | HK | 0.00 | |
B088 | 看见 | 1 | 1015 | T恤 | 300 | 53*33*53 | HK | 3.27 |
K032 | 口岸 | 0916 | T恤 | 31 | 0 | CHINA | 0.00 | |
K032 | 口岸 | 0892 | T恤 | 33 | 0 | CHINA | 0.00 | |
K032 | 口岸 | 0922 | T恤 | 43 | 0 | CHINA | 0.00 | |
K032* | 口岸 | 1 | 0927 | T恤 | 50 | 65*38*67 | CHINA* | 5.84 |
K034 | 口岸 | 1 | 5042 | T恤 | 75 | 65*38*50 | CHINA | 4.36 |
A175 | 来来 | 1 | 535 | T恤 | 25 | 53*33*19 | CHINA | 1.17 |
A186 | 来来 | 1 | 0622 | T恤 | 50 | 53*33*53 | CHINA | 3.27 |
A186 | 来来 | 689 | T恤 | 20 | 0 | CHINA | 0.00 | |
A186 | 来来 | 8802 | T恤 | 40 | 0 | CHINA | 0.00 | |
B089 | 来来 | 1 | 310 | T恤 | 60 | 53*33*26 | HK | 1.61 |
K033 | 来来 | 1 | 881 | T恤 | 80 | 53*33*76 | CHINA | 4.69 |
K035 | 来来 | 1 | 6857 | T恤 | 60 | 65*38*67 | CHINA | 5.84 |
K035 | 来来 | 6858 | T恤 | 60 | 0 | CHINA | 0.00 | |
K035 | 来来 | 6852 | T恤 | 90 | 0 | CHINA | 0.00 | |
K046 | 来来 | 1 | 1287 | T恤 | 60 | 80*50*60 | CHINA | 8.48 |
K046 | 来来 | 1315 | T恤 | 45 | 0 | CHINA | 0.00 | |
K046 | 来来 | 2671 | T恤 | 30 | 0 | CHINA | 0.00 | |
K046 | 来来 | 666 | T恤 | 10 | 0 | CHINA | 0.00 | |
K047 | 来来 | 1 | 666 | T恤 | 100 | 65*38*67 | CHINA | 5.84 |
K047 | 来来 | 702 | T恤 | 79 | 0 | CHINA | 0.00 | |
K009 | 脸仍 | 1 | 3047 | T恤 | 24 | 61*35*27 | CHINA | 2.04 |
K010 | 脸仍 | 1 | 3047 | T恤 | 24 | 61*35*27 | CHINA | 2.04 |
K011 | 脸仍 | 1 | 36P10 | T恤 | 24 | 61*35*27 | CHINA | 2.04 |
K012 | 脸仍 | 1 | 36P10 | T恤 | 24 | 61*35*27 | CHINA | 2.04 |
K013 | 脸仍 | 1 | 38P32 | T恤 | 24 | 61*35*27 | CHINA | 2.04 |
K014 | 脸仍 | 1 | 38P32 | T恤 | 24 | 61*35*27 | CHINA | 2.04 |
K015 | 脸仍 | 1 | 38P11 | T恤 | 24 | 61*35*27 | CHINA | 2.04 |
K016 | 脸仍 | 1 | 38P11 | T恤 | 24 | 61*35*27 | CHINA | 2.04 |
K017 | 脸仍 | 1 | 38P22 | T恤 | 24 | 61*35*27 | CHINA | 2.04 |
K018 | 脸仍 | 1 | 38P22 | T恤 | 24 | 61*35*28 | CHINA | 2.11 |
K019 | 脸仍 | 1 | 37P49 | T恤 | 24 | 61*35*28 | CHINA | 2.11 |
K020 | 脸仍 | 1 | 37P49 | T恤 | 24 | 61*35*28 | CHINA | 2.11 |
K021 | 脸仍 | 1 | 34P21 | T恤 | 24 | 61*35*28 | CHINA | 2.11 |
K022 | 脸仍 | 1 | 34P21 | T恤 | 24 | 61*35*28 | CHINA | 2.11 |
K023 | 脸仍 | 1 | 38P22* | T恤 | 24 | 61*35*32 | CHINA | 2.41 |
K024 | 脸仍 | 1 | 38P22* | T恤 | 24 | 61*35*32 | CHINA | 2.41 |
K025 | 脸仍 | 1 | 38P32* | T恤 | 24 | 61*35*32 | CHINA | 2.41 |
K026 | 脸仍 | 1 | 38P32* | T恤 | 24 | 61*35*32 | CHINA | 2.41 |
K027 | 脸仍 | 1 | 35P69 | T恤 | 24 | 61*35*32 | CHINA | 2.41 |
K028 | 脸仍 | 1 | 35P69 | T恤 | 24 | 61*35*32 | CHINA | 2.41 |
K044 | 脸仍 | 1 | * | T恤 | 48 | 53*33*76 | CHINA | 4.69 |
K045 | 脸仍 | 1 | / | T恤 | 72 | 53*33*76 | CHINA | 4.69 |
K029 | 邻居 | 1 | 38P22 | T恤 | 24 | 61*35*32 | CHINA | 2.41 |
K030 | 邻居 | 1 | 38P22 | T恤 | 24 | 61*35*32 | CHINA | 2.41 |
K031 | 邻居 | 1 | 38P22 | T恤 | 24 | 61*35*32 | CHINA | 2.41 |
A148 | 你 | 1 | 3385 | T恤 | 121 | 70*50*50 | CHINA | 6.18 |
A148 | 你 | 3404 | T恤 | 120 | 0 | CHINA | 0.00 | |
J001 | 潘茄 | 1 | 721-2 | T恤 | 35 | 80*50*60 | B/CHINA | 8.48 |
J001 | 潘茄 | 721-10 | T恤 | 13 | 0 | B/CHINA | 0.00 | |
J002 | 潘茄 | 1 | 721-10 | T恤 | 22 | 80*50*60 | B/CHINA | 8.48 |
J002 | 潘茄 | 723-1 | T恤 | 25 | 0 | B/CHINA | 0.00 | |
J003 | 潘茄 | 1 | 723-1 | T恤 | 15 | 80*50*60 | B/CHINA | 8.48 |
J003 | 潘茄 | 721-1 | T恤 | 30 | 0 | B/CHINA | 0.00 | |
J003 | 潘茄 | 778-2 | T恤 | 2 | 0 | B/CHINA | 0.00 | |
J004 | 潘茄 | 1 | 778-2 | T恤 | 28 | 65*38*60 | B/CHINA | 5.23 |
K007 | 潘茄 | 1 | 4301 | T恤 | 220 | 53*33*76 | CHINA | 4.69 |
K008 | 潘茄 | 1 | 108-15 | T恤 | 15 | 80*50*60 | B/CHINA | 8.48 |
K008 | 潘茄 | 108-3 | T恤 | 15 | 0 | B/CHINA | 0.00 | |
K008 | 潘茄 | 108-19A | T恤 | 15 | 0 | B/CHINA | 0.00 | |
K008 | 潘茄 | 7255-1 | T恤 | 3 | 0 | B/CHINA | 0.00 | |
K009 | 潘茄 | 1 | 7255-1 | T恤 | 12 | 65*38*70 | B/CHINA | 6.11 |
K009 | 潘茄 | 8258-2 | T恤 | 20 | 0 | B/CHINA | 0.00 | |
K01* | 潘茄 | 1 | 4301 | T恤 | 220 | 53*33*76 | CHINA* | 4.69 |
K02* | 潘茄 | 1 | 4301 | T恤 | 220 | 53*33*76 | CHINA* | 4.69 |
K03* | 潘茄 | 1 | 4301 | T恤 | 220 | 53*33*76 | CHINA* | 4.69 |
K04* | 潘茄 | 1 | 4301 | T恤 | 220 | 53*33*76 | CHINA* | 4.69 |
K05* | 潘茄 | 1 | 4301 | T恤 | 220 | 53*33*76 | CHINA* | 4.69 |
K06* | 潘茄 | 1 | 4301 | T恤 | 220 | 53*33*76 | CHINA* | 4.69 |
K800* | 潘茄 | 1 | 4301 | T恤 | 230 | 65*38*67 | CHINA* | 5.84 |
L004 | 潘茄 | / | T恤 | -1 | 0 | 0.00 | ||
L004 | 潘茄 | 1 | 2303-F6 | T恤 | 40 | 80*50*50 | B/CHINA | 7.06 |
A187 | 晟 | 1 | 2007-05-17 | T恤 | 174 | 80*50*60 | CHINA | 8.48 |
A187 | 晟 | 2007-05-17 | T恤 | 37 | 0 | CHINA | 0.00 | |
A188 | 晟 | 1 | C7338-A | T恤 | 178 | 80*50*60 | CHINA | 8.48 |
A188 | 晟 | C7334-A | T恤 | 156 | 0 | CHINA | 0.00 | |
A188 | 晟 | C7312-A | T恤 | 5 | 0 | CHINA | 0.00 | |
A189 | 晟 | 1 | 2007-05-17 | T恤 | 50 | 53*33*45 | CHINA | 2.78 |
A149 | 他 | 1 | * | T恤 | 33 | 80*50*50 | CHINA | 7.06 |
A149 | 他 | C7304-A | T恤 | 143 | 0 | CHINA | 0.00 | |
A149 | 他 | C7311-A | T恤 | 122 | 0 | CHINA | 0.00 | |
A149 | 他 | C7312-A | T恤 | 17 | 0 | CHINA | 0.00 | |
A158 | 为为 | 1 | D8001 | T恤 | 201 | 70*50*50 | CHINA | 6.18 |
A158 | 为为 | D8002 | T恤 | 102 | 0 | CHINA | 0.00 | |
A158 | 为为 | D8005 | T恤 | 38 | 0 | CHINA | 0.00 | |
A159 | 为为 | 1 | D8005 | T恤 | 102 | 53*33*42 | CHINA | 2.59 |
A147 | 我 | 1 | 30194 | T恤 | 90 | 80*50*60 | CHINA | 8.48 |
A147 | 我 | 30288 | T恤 | 28 | 0 | CHINA | 0.00 | |
A147 | 我 | 30588 | T恤 | 60 | 0 | CHINA | 0.00 | |
A154 | 一样 | 1 | 980 | T恤 | 11 | 53*33*18 | CHINA | 1.11 |
A154 | 一样 | 986 | T恤 | 14 | 0 | CHINA | 0.00 | |
A154 | 一样 | 987 | T恤 | 20 | 0 | CHINA | 0.00 | |
A165 | 有有 | 1 | 133 | T恤 | 70 | 53*33*53 | CHINA | 3.27 |
A174 | 在在 | 1 | 8028 | T恤 | 30 | 53*33*21 | CHINA | 1.30 |
A156 | 真好 | 1 | 007 | T恤 | 60 | 53*33*76 | CHINA | 4.69 |
A156 | 真好 | 8100 | T恤 | 80 | 0 | CHINA | 0.00 | |
A157 | 真好 | 1 | 701 | T恤 | 80 | 53*33*60 | CHINA | 3.71 |
A157 | 真好 | 9801 | T恤 | 30 | 0 | CHINA | 0.00 | |
A164 | 中一中 | 1 | 3704 | T恤 | 78 | 53*33*52 | CHINA | 3.21 |
A172 | 中一中 | 1 | 810 | T恤 | 50 | 53*33*32 | CHINA | 1.98 |
表2:
custor | xh | jx | zl |
ANDY | A171 | 1 | 8.48 |
hero | K043 | 1 | 4.69 |
爱 | A152,A153 | 2 | 2.97 |
冰冻 | K042 | 1 | 4.01 |
脖子 | A162,A181-A185,B085-B087 | 9 | 37.65 |
不不 | B084 | 1 | 8.48 |
淡淡 | A176-A178 | 3 | 25.44 |
发 | A173 | 1 | 1.05 |
发财 | K036-K038,K041,K048.K40 | 6 | 35.67 |
方方 | A163,B090 | 2 | 5.5 |
工人 | A166-A170 | 5 | 24.94 |
好好 | D045-D049 | 5 | 36.51 |
看见 | B088 | 1 | 3.27 |
口岸 | K032,K034 | 2 | 10.2 |
来来 | A175,A186,B089,K033,K035,K046-K047 | 7 | 30.9 |
烦请各位大侠帮帮小弟忙,在此感谢大家了!
http://www.cnblogs.com/RChen/archive/2006/11/15/sql2k5_clr.html
http://www.7880.com/Info/Article-402d2360.html
这个也许可以帮助你。
SQLServer2000下的话,我现在只能想到用游标实现。
我考虑用代码实现。程序中可以实现的话,不一定要纠结在sql语句上
select custor,sum(zl) zl,count(distinct xh) as jx
,xh=stuff( (select distinct ','+xh from tab_xh b
where b.custor=a.custor
for XML PATH('')),1,1,'')
from tab_xh a group by custor
把from后面的换成你实际的表名