數據我有一種稀有的,以顯示數據,同時考慮到以下各表如下:混亂,以顯示與「馬」和「馬」
mysql> describe materiales;
+-----------+--------------+------+-----+------------+----------------+
| Field | Type | Null | Key | Default | Extra |
+-----------+--------------+------+-----+------------+----------------+
| registro | int(12) | NO | PRI | NULL | auto_increment |
| clave | char(6) | NO | UNI | | |
| clave2 | char(20) | YES | MUL | | |
| descr | char(30) | YES | | | |
| descr2 | char(250) | YES | | | |
| unidad | char(7) | YES | | | |
| presest | double(18,7) | YES | | 0.0000000 | |
| unidadpre | char(7) | YES | | | |
| codbar | char(30) | YES | | | |
| impuesto | double(18,7) | YES | | 0.0000000 | |
| mantpend | tinyint(1) | YES | | 0 | |
| grupplat | char(6) | YES | MUL | | |
| fechalta | date | YES | | 0000-00-00 | |
| usuarmod | char(6) | YES | | | |
| fechamod | date | YES | | 0000-00-00 | |
+-----------+--------------+------+-----+------------+----------------+
mysql> describe grupos;
+----------+----------+------+-----+------------+----------------+
| Field | Type | Null | Key | Default | Extra |
+----------+----------+------+-----+------------+----------------+
| registro | int(12) | NO | PRI | NULL | auto_increment |
| clave | char(6) | NO | UNI | | |
| descr | char(30) | YES | | | |
| fechalta | date | YES | | 0000-00-00 | |
| usuarmod | char(6) | YES | | | |
| fechamod | date | YES | | 0000-00-00 | |
+----------+----------+------+-----+------------+----------------+
要查詢,我只想告訴我的馬只有grupplat但顯示我的馬和馬的見底:
mysql> SELECT CLAVE,DESCR,GRUPPLAT FROM MATERIALES WHERE
grupplat>='MA' AND grupplat<='MA' ORDER BY GRUPPLAT;
+--------+--------------------------------+----------+
| CLAVE | DESCR | GRUPPLAT |
+--------+--------------------------------+----------+
| PE100A | DEDOS QUESO | MA |
| PE125A | FUNKY MONKEY BITES | MA |
| PE125B | LUCKY DOG BOGARTS D-LIGHT | MA |
| PE125C | ROCKY ROAD PEANUT BUTTER BITES | MA |
| PE125D | SIRENAS SEAFOOD MEDLEY | MA |
| PE200A | HOJA TRANSFER | MA |
| PE250A | FRITURA CHURIS | MA |
| PE271A | HAMBURGUESA AMERICANA RES | MA |
| PE271B | HAMBURGUESA AMERICANA JR | MA |
| PE275A | PAPA ADOBADA | MA |
| PE301A | PAPA FRANCESA 1-4 | MA |
| PE304A | PAPA FRANCESA 3-8 | MA |
| PE308A | PAPA FRANCESA 5-16 | MA |
| PE312A | PAPA FRITA | MA |
| PE315A | PAPA GAJO NATURAL | MA |
| PE335A | PAPA HASH TRIANGULO | MA |
| PE370A | POLLO ALITA MARINADA IQF | MA |
| PE385A | POLLO NUGGET | MA |
| PE410A | PIZZA BASE | MA |
| PE411A | PIZZA REDONDA DULCE | MA |
| PE413A | PIZZA DE ZATAR | MA |
| PE450A | VERDURA CONGELADA MIXTA | MA |
| PE510A | WAFLES | MA |
| PF0001 | PRODUCTO FICTICIO | Ma | <--- ERROR
| PF0002 | AGUA POTABLE | Ma | <--- ERROR
| PF0003 | AGUA DE GARRAFON | Ma | <--- ERROR
| PF0004 | HIELO | Ma | <--- ERROR
| PE250F | FRITURA CAZARES | MA |
| PE301H | PAPA FRANCESA 1-2 ONDULADA | MA |
| PE510D | WAFFLES | MA |
| PE271C | HAMBURGUESA ARRACHERA 198 G | MA |
| PE370B | POLLO ALITAS MARINADAS | MA |
+--------+--------------------------------+----------+
,你可以看到,但放在另一個查詢與以下類似下面的語法,只顯示「馬」的數據,但。 ..向我展示'Ma'和'MA'的所有數據
mysql> SELECT CLAVE,DESCR,GRUPPLAT FROM MATERIALES WHERE
grupplat>='Ma' AND grupplat<='Ma' ORDER BY GRUPPLAT;
+--------+--------------------------------+----------+
| CLAVE | DESCR | GRUPPLAT |
+--------+--------------------------------+----------+
| PE100A | DEDOS QUESO | MA |
| PE125A | FUNKY MONKEY BITES | MA |
| PE125B | LUCKY DOG BOGARTS D-LIGHT | MA |
| PE125C | ROCKY ROAD PEANUT BUTTER BITES | MA |
| PE125D | SIRENAS SEAFOOD MEDLEY | MA |
| PE200A | HOJA TRANSFER | MA |
| PE250A | FRITURA CHURIS | MA |
| PE271A | HAMBURGUESA AMERICANA RES | MA |
| PE271B | HAMBURGUESA AMERICANA JR | MA |
| PE275A | PAPA ADOBADA | MA |
| PE301A | PAPA FRANCESA 1-4 | MA |
| PE304A | PAPA FRANCESA 3-8 | MA |
| PE308A | PAPA FRANCESA 5-16 | MA |
| PE312A | PAPA FRITA | MA |
| PE315A | PAPA GAJO NATURAL | MA |
| PE335A | PAPA HASH TRIANGULO | MA |
| PE370A | POLLO ALITA MARINADA IQF | MA |
| PE385A | POLLO NUGGET | MA |
| PE410A | PIZZA BASE | MA |
| PE411A | PIZZA REDONDA DULCE | MA |
| PE413A | PIZZA DE ZATAR | MA |
| PE450A | VERDURA CONGELADA MIXTA | MA |
| PE510A | WAFLES | MA |
| PF0001 | PRODUCTO FICTICIO | Ma |
| PF0002 | AGUA POTABLE | Ma |
| PF0003 | AGUA DE GARRAFON | Ma |
| PF0004 | HIELO | Ma |
| PE250F | FRITURA CAZARES | MA |
| PE301H | PAPA FRANCESA 1-2 ONDULADA | MA |
| PE510D | WAFFLES | MA |
| PE271C | HAMBURGUESA ARRACHERA 198 G | MA |
| PE370B | POLLO ALITAS MARINADAS | MA |
+--------+--------------------------------+----------+
但如果訂單是「GROUP BY」,因爲某些原因不是「馬」,如果我通過查詢,發現該groupplat的個兒顯示我喜歡出現
mysql> SELECT CLAVE,DESCR,GRUPPLAT FROM MATERIALES group BY grupplat;
+--------+--------------------------------+----------+
| CLAVE | DESCR | GRUPPLAT |
+--------+--------------------------------+----------+
| AB002A | ACEITE DE CACAHUATE | M0 |
| AV005A | HUEVO | M1 |
| CR005A | CERDO BISTEC | M2 |
| EM010A | CERDO CHORIZO | M3 |
| ES005A | ACHIOTE | M4 |
| FV003A | ACELGA | M5 |
| LA010A | CREMA ACIDA | M6 |
| PN010A | BISQUET DULCE 30 G | M7 |
| PA010A | CAPELLINI | M8 |
| PM005A | ALMEJA CHIRLA | M9 |
| PE100A | DEDOS QUESO | MA |
| PO010A | ACEITE DE AJONJOLI PICANTE | MB |
| TT050A | MASA DE MAIZ | MC |
| PT010A | BROWNIE | MD |
| HN010A | HELADO BANANA BLU | ME |
| AR005A | AGUA NATURAL 355 ML | MI |
| CA010A | CAFE CAREY GOURMET GRANO | MJ |
| CO025A | GINSENG AMPOLLETA | ML |
| TE005A | TE AMANECER | MM |
| CE010A | BOHEMIA 355 ML | MN |
| AN005A | ANIS CHINCHON DULCE | MO |
| BR010A | BRANDY AZTECA DE ORO | MP |
| CV070A | CH MOET CHANDON DOM PERIGNON | MQ |
| CG010A | COGNAC COURVOISIER V.S.O.P | MR |
| CL002A | AGUARDIENTE CACHACA | MS |
| GI015A | GINEBRA BEEFEATER | MT |
| RO010A | RON APPLETON BLANCO | MU |
| TQ010A | MEZ ALIPUS SAN ANDRES | MV |
| VO020A | VODKA ABSOLUT | MW |
| WH010A | WHISKY BALLANTINES FINEST | MX |
| VB010A | VB ALBERT BICHOT CHABLIS | MY |
| VR050A | VR CERAUSOLO TOSE D ABRUZZO LA | MZ |
+--------+--------------------------------+----------+
組的表
這樣的:
mysql> SELECT registro,clave,descr FROM compras.grupos group by clave;
+----------+-------+----------------------+
| registro | clave | descr |
+----------+-------+----------------------+
| 3 | M0 | ABARROTES |
| 4 | M1 | AVES |
| 5 | M2 | CARNES ROJAS |
| 6 | M3 | EMBUTIDOS |
| 7 | M4 | ESPECIAS-SECOS |
| 8 | M5 | FRUTAS-VERDURAS |
| 9 | M6 | LACTEOS |
| 10 | M7 | PANES |
| 11 | M8 | PASTAS |
| 12 | M9 | PESCADOS-MARISCOS |
| 13 | MA | PRODUCTOS ELABORADOS |
| 14 | MB | PRODUCTOS ORIENTALES |
| 15 | MC | TORTILLAS |
| 16 | MD | PASTELES |
| 17 | ME | HELADOS-NIEVES |
| 18 | MF | PRODUCTOS EXOTICOS |
| 19 | MI | AGUAS-REFRESCOS |
| 20 | MJ | CAFES |
| 21 | MK | CHOCOLATES FRAPPES |
| 22 | ML | COMPLEMENTOS ALIMENT |
| 23 | MM | TES |
| 24 | MN | CERVEZAS |
| 25 | MO | ANISES |
| 26 | MP | BRANDYS |
| 27 | MQ | CHAMPAGNES-VINOS ES |
| 28 | MR | COGNACS |
| 29 | MS | CREMAS-LICORES-OPORT |
| 30 | MT | GINEBRAS |
| 31 | MU | RONES |
| 32 | MV | TEQUILAS |
| 33 | MW | VODKAS |
| 34 | MX | WHISKYS |
| 35 | MY | VINOS BLANCOS |
| 36 | MZ | VINOS TINTOS |
| 37 | Ma | AGREGADOS |
+----------+-------+----------------------+
所以......不,如果我不得不改變或是否刪除MATERIALES表的關鍵「MUL」看到,因爲當我做組「馬雲的查詢,如果「解決問題」 '沒有表演......但'馬'是的...所以我已經非常沮喪,我發現這個非常惱人的錯誤!因爲我用這個另一個查詢連接表,我需要向用戶展示與內餐廳加入,但我提出這個問題,因爲MYSQL,因爲它不顯示馬...得到它像MA
SELECT * FROM DETOC INNER JOIN MATERIALES ON DETOC.MATERIAL = MATERIALES.CLAVE
INNER JOIN GRUPOS ON MATERIALES.GRUPPLAT = GRUPOS.CLAVE
INNER JOIN ORDENESCOMPRA ON DETOC.ORDCOMP = ORDENESCOMPRA.CLAVE
INNER JOIN PROVEEDORES ON ORDENESCOMPRA.CVEPROV = PROVEEDORES.CLAVE
INNER JOIN AREAS ON ORDENESCOMPRA.AREA = AREAS.CLAVE
WHERE ORDENESCOMPRA.FECHALTA>='2014-01-01' AND ORDENESCOMPRA.FECHALTA<='2015-01-19'
AND ORDENESCOMPRA.AREA>=' 50' AND ORDENESCOMPRA.AREA<=' AF2'
AND ORDENESCOMPRA.CVEPROV>='000004' AND ORDENESCOMPRA.CVEPROV<='011551'
AND MATERIALES.CLAVE>='AB002A' AND MATERIALES.CLAVE<='WH420A'
AND MATERIALES.GRUPPLAT>='M0' AND MATERIALES.GRUPPLAT<='Ma'
AND ORDENESCOMPRA.CLAVE>='8780' AND ORDENESCOMPRA.CLAVE<='8790';
更新它們是一樣的嗎? – robert 2015-01-20 18:35:20
您需要將表格更改爲區分大小寫的排序規則。否則,在比較和分組中,'MA'和'Ma'被視爲等價物。 – Barmar 2015-01-20 18:36:47
嘗試'WHERE grupplat COLLATE latin1_general_cs> ='MA'AND grupplat COLLATE latin1_general_cs <='MA'' – Mihai 2015-01-20 18:37:12