我有以下表格:
CREATE TABLE [dbo].[Clientes](
[IdCliente] [int] IDENTITY(1,1) NOT NULL,
[ApellidoPaterno] [varchar](max) NULL,
[ApellidoMaterno] [varchar](max) NULL,
[Nombre] [varchar](max) NULL,
[Empresa] [text] NULL,
[Estado] [varchar](20) NULL,
CONSTRAINT [PK_Clientes] PRIMARY KEY CLUSTERED
)
CREATE TABLE [dbo].[DatosLegales](
[IdDatoLegal] [int] IDENTITY(1,1) NOT NULL,
[IdCliente] [int] NULL,
[Nombre] [varchar](max) NULL,
[RFC] [varchar](20) NULL,
CONSTRAINT [PK_DatosLegales] PRIMARY KEY CLUSTERED
)
CREATE TABLE [dbo].[Facturas](
[IdFactura] [int] IDENTITY(1,1) NOT NULL,
[IdCliente] [int] NULL,
[IdDatoLegal] [int] NULL,
[Serie] [varchar](20) NULL,
[Folio] [varchar](20) NULL,
[UUID] [varchar](50) NULL,
[FechaEmision] [date] NULL,
[HoraEmision] [varchar](10) NULL,
[RutaXML] [varchar](max) NULL,
[RutaCBB] [varchar](max) NULL,
[RutaPDF] [varchar](max) NULL,
[Estado] [varchar](50) NULL,
CONSTRAINT [PK_Facturas] PRIMARY KEY CLUSTERED
)
Clientes.IdCliente 上的外键 = DatosLegales.IdCliente DatosLegales.IdDatoLegal = Facturas.IdDatoLegal
我正在使用以下查询
SELECT Facturas.IdFactura, Facturas.IdGrupo, (Clientes.ApellidoPaterno + ' ' + Clientes.ApellidoMaterno + ' ' + Clientes.Nombre) AS Cliente, DatosLegales.Nombre, Facturas.Serie, Facturas.Folio, Facturas.UUID, Facturas.Estado, Facturas.FechaEmision, Facturas.HoraEmision
FROM Facturas
INNER JOIN Ventas ON (Facturas.IdFactura = Ventas.IdFactura)
INNER JOIN Clientes ON (Clientes.IdCliente = Ventas.IdCliente)
INNER JOIN DatosLegales ON (DatosLegales.IdDatoLegal = Facturas.IdDatoLegal)
WHERE Facturas.IdGrupo = 1 AND (Clientes.ApellidoPaterno + ' ' + Clientes.ApellidoMaterno + ' ' + Clientes.Nombre LIKE '%55%' OR Clientes.Nombre + ' ' + Clientes.ApellidoPaterno + ' ' + Clientes.ApellidoMaterno LIKE '%55%' OR DatosLegales.Nombre LIKE '%55%' OR Facturas.Serie LIKE '%55%' OR Facturas.Folio LIKE '%55%' OR Facturas.UUID LIKE '%55%' OR Facturas.IdFactura LIKE '%55%')
ORDER BY IdFactura DESC
而且我得到一个特定的行至少三遍......我认为这是因为(因为我使用 Like%55%)对于 55 上的每场比赛它都会显示该行。但是我只需要显示这些行一次。我能做些什么来解决这个问题?提前致谢。