gpt4 book ai didi

mysql - 使用 'MA' 和 'Ma' 显示数据时出现困惑

转载 作者:行者123 更新时间:2023-11-29 12:27:40 26 4
gpt4 key购买 nike

考虑到下表,我对显示数据有一种罕见的态度:

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上显示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 | <--- 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”和“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”,由于某种原因,“Ma”不会显示为

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 |
+--------+--------------------------------+----------+

在组表中,如果我查询以查看组平台的 clave,则显示如下:

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 |
+----------+-------+----------------------+

所以...如果我必须更改或是否删除 Material 表的键“MUL”以查看是否“解决问题”,因为当我对“Ma”组进行查询时没有显示...但是“MA”是的...所以我已经非常沮丧,因为我发现这个非常烦人的错误!因为我使用另一个查询来连接表,所以我需要向用户显示具有内部连接的餐厅,但我提交此错误是因为 MYSQL 因为它不显示 Ma ... 得到它就像 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';

最佳答案

在不区分大小写的数据库中,“MA”和“Ma”和“ma”完全相同。

如果您希望始终以不同的方式对待它们,则应该使表或列或数据库区分大小写。请注意,这对您和您的特定查询的影响要大得多,因此请确保业务需求,并确保为数据库开发的所有其他人都了解可能的更改,并在升级到产品之前在 QA 中充分运用数据库。

如果您只是偶尔需要区分大小写,则可以在查询中使用排序规则。但请注意,这会增加查询的额外时间,并且您必须对需要区分大小写的每个查询执行此操作。如果所有查询都需要这样做,那么它必须在数据库中完成。

在 sql server 中,您可以将排序规则设置应用于单个列,但我不知道这在 mysql 中是否可行。我也不知道当基础表不区分大小写时是否可以创建一个区分大小写的 View 。但这值得尝试。

关于mysql - 使用 'MA' 和 'Ma' 显示数据时出现困惑,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28052649/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com