我正在使用Qlik Sense Desktop来创建报告。 但是,我想使用此请求加载数据:
WITH ventes AS (SELECT Reservations.re_numero AS IDSession, InscriptionsLignes.il_montantLigneHT AS VenteSession, Reservations.re_nom AS NomSession, Tiers.ti_nom AS NomClient, CASE WHEN Tiers_2.ti_nom + ' ' + Tiers_2.ti_prenom IS NULL THEN 'Non affecté' ELSE Tiers_2.ti_nom + ' ' + Tiers_2.ti_prenom END AS NomCommercial
FROM Reservations INNER JOIN
InscriptionsEntetes ON Reservations.re_numero = InscriptionsEntetes.in_reservation INNER JOIN
InscriptionsLignes ON InscriptionsEntetes.in_numero = InscriptionsLignes.il_inscription INNER JOIN
InscriptionsTiers ON InscriptionsEntetes.in_numero = InscriptionsTiers.it_inscription AND InscriptionsLignes.il_inscription = InscriptionsTiers.it_inscription INNER JOIN
Tiers ON InscriptionsTiers.it_tiers = Tiers.ti_identifiant LEFT OUTER JOIN
Tiers AS Tiers_2 ON InscriptionsEntetes.in_idTiersConseiller = Tiers_2.ti_identifiant
WHERE (InscriptionsTiers.it_typeRattachement = '01') AND (Reservations.re_etat <> 3) AND (Reservations.re_annulation = 0) AND (InscriptionsEntetes.in_Etat <> '4')), couts AS
(SELECT Reservations_1.re_numero AS IDSession, ReservationsProduits.rp_montantPrevu AS Couts
FROM Reservations AS Reservations_1 INNER JOIN
ReservationsProduits ON Reservations_1.re_numero = ReservationsProduits.rp_numeroReservation
WHERE (Reservations_1.re_etat <> 3) AND (Reservations_1.re_annulation = 0)), tot_couts AS
(SELECT IDSession, SUM(Couts) AS couts_total
FROM couts AS couts_1
GROUP BY IDSession), tot_ventes AS
(SELECT IDSession, SUM(VenteSession) AS ventes_total
FROM ventes AS ventes_1
GROUP BY IDSession)
SELECT tvn.IDSession, tvn.ventes_total, tct.couts_total, ventes_2.NomSession, ventes_2.NomClient, ventes_2.VenteSession, ventes_2.VenteSession - tct.couts_total / (tvn.ventes_total / ventes_2.VenteSession) AS marge
FROM tot_ventes AS tvn INNER JOIN
tot_couts AS tct ON tvn.IDSession = tct.IDSession INNER JOIN
ventes AS ventes_2 ON tvn.IDSession = ventes_2.IDSession
WHERE (ventes_2.VenteSession <> 0)
ORDER BY tvn.IDSession
正如您所看到的,我使用了SQL With Statement但它并不适用于Qlik,&#34;使用&#34;他们说是一个未知的陈述
任何人都可以帮助我吗?
答案 0 :(得分:1)
如果你之前使用过SQL语句,有些sql命令只是在Qlik中重新识别,例如:
表名: 加载*; SQL;
TableName:
LOAD *;
SQL
WITH ventes AS (
SELECT Reservations.re_numero AS IDSession
, InscriptionsLignes.il_montantLigneHT AS VenteSession
, Reservations.re_nom AS NomSession
, Tiers.ti_nom AS NomClient
, CASE
WHEN Tiers_2.ti_nom + ' ' + Tiers_2.ti_prenom IS NULL
THEN 'Non affecté'
ELSE Tiers_2.ti_nom + ' ' + Tiers_2.ti_prenom
END AS NomCommercial
FROM Reservations
INNER JOIN InscriptionsEntetes
ON Reservations.re_numero = InscriptionsEntetes.in_reservation
INNER JOIN InscriptionsLignes
ON InscriptionsEntetes.in_numero = InscriptionsLignes.il_inscription
INNER JOIN InscriptionsTiers
ON InscriptionsEntetes.in_numero = InscriptionsTiers.it_inscription
AND InscriptionsLignes.il_inscription = InscriptionsTiers.it_inscription
INNER JOIN Tiers
ON InscriptionsTiers.it_tiers = Tiers.ti_identifiant
LEFT OUTER JOIN Tiers AS Tiers_2
ON InscriptionsEntetes.in_idTiersConseiller = Tiers_2.ti_identifiant
WHERE (InscriptionsTiers.it_typeRattachement = '01')
AND (Reservations.re_etat 3)
AND (Reservations.re_annulation = 0)
AND (InscriptionsEntetes.in_Etat '4'))
, couts AS
(SELECT Reservations_1.re_numero AS IDSession
, ReservationsProduits.rp_montantPrevu AS Couts
FROM Reservations AS Reservations_1
INNER JOIN ReservationsProduits
ON Reservations_1.re_numero = ReservationsProduits.rp_numeroReservation
WHERE (Reservations_1.re_etat 3)
AND (Reservations_1.re_annulation = 0)), tot_couts AS
(SELECT IDSession, SUM(Couts) AS couts_total
FROM couts AS couts_1
GROUP BY IDSession), tot_ventes AS
(SELECT IDSession, SUM(VenteSession) AS ventes_total
FROM ventes AS ventes_1
GROUP BY IDSession)
SELECT tvn.IDSession
, tvn.ventes_total
, tct.couts_total
, ventes_2.NomSession
, ventes_2.NomClient
, ventes_2.VenteSession
, ventes_2.VenteSession - tct.couts_total / (tvn.ventes_total / ventes_2.VenteSession) AS marge
FROM tot_ventes AS tvn
INNER JOIN tot_couts AS tct
ON tvn.IDSession = tct.IDSession
INNER JOIN ventes AS ventes_2
ON tvn.IDSession = ventes_2.IDSession
WHERE (ventes_2.VenteSession 0)
ORDER BY tvn.IDSession;
答案 1 :(得分:0)
您可以将查询封装在父查询中:
TableName:
Load *;
SQL
select *
from (
--put your WITH query here
) as temp;
根据您的RDBMS,您可能不需要这个最终别名(&#34;作为temp&#34;)。