Select query taking lot of time to execute - oracle11g

I have this query in my application
SELECT
/*+ parallel (4) */
a.orgkey AS cifid,
a.strfield19 AS old_cif_id,
a.cust_first_name,
a.cust_middle_name,
a.cust_last_name,
a.primary_sol_id AS sol_id,
(
SELECT lang.localetext
FROM crmuser.categories cat,
crmuser.category_lang lang
WHERE cat.categoryid=lang.categoryid
AND cat.categorytype= 'PERSONSALUTATION'
AND cat.bank_id =
(
SELECT bank_id
FROM migadm.migr_det)
AND lang.bank_id =
(
SELECT bank_id
FROM migadm.migr_det)
AND cat.value= a.salutation) AS saluatation,
a.segmentation_class AS segmentation_class,
CASE
WHEN corp_id IS NULL THEN
(
SELECT lang.localetext
FROM crmuser.categories cat,
crmuser.category_lang lang
WHERE cat.categoryid=lang.categoryid
AND cat.categorytype= 'SEGMENTATION_CLASS'
AND cat.bank_id =
(
SELECT bank_id
FROM migadm.migr_det)
AND lang.bank_id =
(
SELECT bank_id
FROM migadm.migr_det)
AND cat.value= a.segmentation_class)
ELSE
(
SELECT lang.localetext
FROM crmuser.categories cat,
crmuser.category_lang lang
WHERE cat.categoryid=lang.categoryid
AND cat.categorytype= 'CORP_SEGMENTATION_CLASS'
AND cat.bank_id =
(
SELECT bank_id
FROM migadm.migr_det)
AND lang.bank_id =
(
SELECT bank_id
FROM migadm.migr_det)
AND cat.value= a.segmentation_class)
END AS segmentation_desc,
a.subsegment AS subsegment,
CASE
WHEN corp_id IS NULL THEN
(
SELECT lang.localetext
FROM crmuser.categories cat,
crmuser.category_lang lang
WHERE cat.categoryid=lang.categoryid
AND cat.categorytype= 'SUB_SEGMENT'
AND cat.bank_id =
(
SELECT bank_id
FROM migadm.migr_det)
AND lang.bank_id =
(
SELECT bank_id
FROM migadm.migr_det)
AND cat.value= a.subsegment)
ELSE
(
SELECT lang.localetext
FROM crmuser.categories cat,
crmuser.category_lang lang
WHERE cat.categoryid=lang.categoryid
AND cat.categorytype= 'CORP_SUB_SEGMENT'
AND cat.bank_id =
(
SELECT bank_id
FROM migadm.migr_det)
AND lang.bank_id =
(
SELECT bank_id
FROM migadm.migr_det)
AND cat.value= a.subsegment)
END AS subsegment_desc,
CASE
WHEN a.corp_id IS NULL THEN a.strfield10
ELSE c.struserfield4
END AS reserve_bank_code,
CASE
WHEN a.corp_id IS NULL THEN a.strfield11
ELSE c.struserfield5
END AS form50_code,
a.sector AS pri_sic_code,
a.subsector AS sec_sic_code,
CASE
WHEN a.corp_id IS NULL THEN a.struserfield3
ELSE c.struserfield3
END AS kyc_indicator,
a.defaultaddresstype AS defaultaddresstype,
b.address_line1,
b.address_line2,
b.address_line3,
CASE
WHEN a.corp_id IS NULL THEN
(
SELECT (ad.address_line1
||' '
||ad.address_line2
||' '
||ad.address_line3)
FROM crmuser.address ad
WHERE a.orgkey=ad.orgkey
AND ad. preferredaddress='Y'
AND
(
SELECT migration_date
FROM migadm.migr_det) BETWEEN ad.start_date AND ad.end_date)
ELSE
(
SELECT (ad.address_line1
||' '
||ad.address_line2
||' '
||ad.address_line3)
FROM crmuser.address ad
WHERE a.orgkey=ad.orgkey
AND ad.preferredaddress='Y' and
(
SELECT migration_date
FROM migadm.migr_det) BETWEEN ad.start_date AND ad.end_date)
END AS postal_adress,
b.zip AS postal_code,
a.gender AS gender,
a.cust_dob AS date_of_birth,
(
SELECT p.email
FROM crmuser.phoneemail p
WHERE p.orgkey = a.orgkey
AND p.preferredflag='Y'
AND phoneoremail='EMAIL'
AND ROWNUM =1) email_id,
(
SELECT p.phonenocountrycode
FROM crmuser.phoneemail p
WHERE p.orgkey = a.orgkey
AND p.preferredflag='Y'
AND phoneoremail='PHONE'
AND ROWNUM =1) AS phone_cntry_code,
(
SELECT p.phonenocitycode
FROM crmuser.phoneemail p
WHERE p.orgkey = a.orgkey
AND p.preferredflag='Y'
AND phoneoremail='PHONE'
AND ROWNUM =1) AS phone_city_code,
(
SELECT '+'
|| p.phonenocountrycode
|| '('
|| p.phonenocitycode
|| ')'
|| p.phonenolocalcode
FROM crmuser.phoneemail p
WHERE p.orgkey = a.orgkey
AND p.preferredflag = 'Y'
AND phoneoremail='PHONE') phone_no,
--CASE WHEN (SELECT COUNT(1) FROM crmuser.miscellaneousinfo m WHERE a.orgkey=m.orgkey and type = 'CURRENCY') = 1 THEN (SELECT strtext10 FROM crmuser.miscellaneousinfo m WHERE a.orgkey=m.orgkey and type = 'CURRENCY')
-- WHEN (SELECT COUNT(1) FROM crmuser.corpmiscellaneousinfo m WHERE a.orgkey=m.orgkey and type = 'CURRENCY') = 1 THEN (SELECT str1 FROM crmuser.corpmiscellaneousinfo m WHERE a.orgkey=m.orgkey and type = 'CURRENCY')
-- ELSE
migadm.getcurrencies(a.orgkey)
--END
AS crncy_code,
CASE
WHEN a.corp_id IS NULL THEN a.struserfield15
ELSE c.struserfield6
END AS wht_indicator,
a.cust_swift_code_desc AS cust_swift_code_desc,
customernreflg AS customernreflg,
(
SELECT employerid
FROM crmuser.miscellaneousinfo s
WHERE s.orgkey = a.orgkey
AND TYPE ='CURRENT_EMPLOYMENT') AS group_number,
(
SELECT strtext4
FROM crmuser.miscellaneousinfo s
WHERE s.orgkey = a.orgkey
AND TYPE ='CURRENT_EMPLOYMENT' ) AS employment_details,
--(select EMPLOYERSNAME from crmuser.DEMOGRAPHIC s where s.orgkey = a.orgkey ) AS employment_details,
(
SELECT employeeid
FROM crmuser.miscellaneousinfo s
WHERE s.orgkey = a.orgkey
AND TYPE ='CURRENT_EMPLOYMENT' ) AS employeeid,
--(select EMPLOYERID from crmuser.MISCELLANEOUSINFO s where s.orgkey = a.orgkey ) AS employerid,
a.manager AS manager,
CASE
WHEN a.corp_id IS NULL THEN d.annual_salary_income
ELSE c.average_annualincome
END AS annual_income,
c.registration_number
FROM crmuser.corporate c
right join crmuser.address b
ON b.orgkey=c.corp_key
right join crmuser.accounts a
ON b.orgkey=a.orgkey
left join crmuser.demographic d
ON a.orgkey=d.orgkey
WHERE a.bank_id =
(
SELECT bank_id
FROM migadm.migr_det)
AND a.entity_cre_flag = 'Y'
AND b.preferredaddress = 'Y'
It takes more than 20 minutes to give results. Can someone please help me in tuning this query. I don't have any idea about sql.
I can give the explain plan needed but I don't know how to copy here the 111 rows from plan table

Related

- ORA-01407: cannot update ("PSOWNER"."PS_VCHR_LINE_STG"."CLASS_FLD") to NULL Failed SQL stmt: UPDATE

Error Message:- ORA-01407: cannot update ("PSOWNER"."PS_VCHR_LINE_STG"."CLASS_FLD") to NULL Failed SQL stmt: UPDATE
When I am generating the report it is saying NO Success in Peoplesoft.
Below is the code for the Update statement.
Please help me how to overcome this problem.
UPDATE %Table(VCHR_LINE_STG) A
SET A.CLASS_FLD = (
SELECT SUBSTR(DCP_FLD49
,3
,4)
FROM %Table(DCP_AP11_TMP2)
WHERE VCHR_BLD_KEY_C1 = A.VCHR_BLD_KEY_C1
AND DCP_FLD34= A.VOUCHER_LINE_NUM),A.BUSINESS_UNIT =(
SELECT D.CF_ATTRIB_VALUE
FROM %Table(CF_ATTRIB_TBL) D
, %Table(DEPT_TBL) E
WHERE ( D.EFFDT = (
SELECT MAX(D_ED.EFFDT)
FROM %Table(CF_ATTRIB_TBL) D_ED
WHERE D.SETID = D_ED.SETID
AND D.CHARTFIELD_VALUE = D_ED.CHARTFIELD_VALUE
AND D_ED.EFFDT <= SYSDATE)
AND E.EFFDT=D.EFFDT
AND D.CHARTFIELD_VALUE = (
SELECT M.DCP_FLD41
FROM %Table(DCP_AP11_TMP2) M
WHERE M.VCHR_BLD_KEY_C1 = A.VCHR_BLD_KEY_C1
AND M.DCP_FLD34= A.VOUCHER_LINE_NUM)
AND D.SETID = E.SETID
AND D.SETID = 'DCPID'
AND D.CF_ATTRIBUTE='AP_BUSN_UNIT'
AND E.EFFDT = (
SELECT MAX(E_ED.EFFDT)
FROM %Table(DEPT_TBL) E_ED
WHERE E.SETID = E_ED.SETID
AND E.DEPTID = E_ED.DEPTID
AND E_ED.EFFDT <= SYSDATE)
AND E.DEPTID = D.CHARTFIELD_VALUE
AND E.SETID = D.SETID
AND E.EFF_STATUS='A')),A.BUSINESS_UNIT_GL=(
SELECT D.CF_ATTRIB_VALUE
FROM %Table(CF_ATTRIB_TBL) D
, %Table(DEPT_TBL) E
WHERE ( D.EFFDT = (
SELECT MAX(D_ED.EFFDT)
FROM %Table(CF_ATTRIB_TBL) D_ED
WHERE D.SETID = D_ED.SETID
AND D.CHARTFIELD_VALUE = D_ED.CHARTFIELD_VALUE
AND D_ED.EFFDT <= SYSDATE)
AND E.EFFDT=D.EFFDT
AND D.CHARTFIELD_VALUE = (
SELECT M.DCP_FLD41
FROM %Table(DCP_AP11_TMP2) M
WHERE M.VCHR_BLD_KEY_C1 = A.VCHR_BLD_KEY_C1
AND M.DCP_FLD34= A.VOUCHER_LINE_NUM)
AND D.SETID = E.SETID
AND D.SETID = 'DCPID'
AND D.CF_ATTRIBUTE='GL_BUSN_UNIT'
AND E.EFFDT = (
SELECT MAX(E_ED.EFFDT)
FROM %Table(DEPT_TBL) E_ED
WHERE E.SETID = E_ED.SETID
AND E.DEPTID = E_ED.DEPTID
AND E_ED.EFFDT <= SYSDATE)
AND E.DEPTID = D.CHARTFIELD_VALUE
AND E.SETID = D.SETID
AND E.EFF_STATUS='A'))
WHERE EXISTS (
SELECT 'X'
FROM %Table(DCP_AP11_TMP2)
WHERE VCHR_BLD_KEY_C1 = A.VCHR_BLD_KEY_C1
AND VOUCHER_LINE_NUM = A.VOUCHER_LINE_NUM)
Above is the code for the Update statement in App engine.
Please help me how to overcome this problem.
Thanks in Advance.
The sub-selects populating each field are not returning values so the database is trying to update the field to NULL. In PeopleSoft null values are not allowed in character fields. A field with no value needs to be set to a single space, like ' '.
You will need to wrap each sub-select with a COALESCE() function, with a non-null alternative option if the sub-select does not return a value. Character fields need to be set to ' ', numbers to 0 if no values returned. Date fields can be null. Here is an example using the first few lines of the code provided.
UPDATE %Table(VCHR_LINE_STG) A
SET A.CLASS_FLD =
COALESCE(
(SELECT SUBSTR(DCP_FLD49,3,4)
FROM %Table(DCP_AP11_TMP2)
WHERE VCHR_BLD_KEY_C1 = A.VCHR_BLD_KEY_C1
AND DCP_FLD34= A.VOUCHER_LINE_NUM), ' ')
, A.BUSINESS_UNIT_GL=(SELECT
...

MSDAX 2012 Onhand Calculation from InventSum & InventTrans tables

I have used the below query to calculate the onhand quantity from InventTrans table but that onhand does not match with the AvailPhysical and/or PhysicalInvent of InventSum table. I have tried matching with other quantities as well but onhand is not matching. Please guide me what am i missing here
SELECT T1.ITEMID AS ITEMID
,T1.QTY
,T1.INVENTDIMID AS INVENTDIMID
,DATEDIFF(dd, T3.TRANSDATE, getdate()) AS Age
,t19.price as RetailPrice
,t1.CurrencyCode AS CurrencyKey
,T1.DATAAREAID AS DATAAREAID
,T1.PARTITION AS PARTITION
FROM INVENTTRANS T1
LEFT JOIN INVENTTRANSORIGIN T2 ON (
T1.INVENTTRANSORIGIN = T2.RECID
AND (T1.DATAAREAID = T2.DATAAREAID)
AND (T1.PARTITION = T2.PARTITION)
)
INNER JOIN INVENTTRANSPOSTING T3 ON (
(
(
(
T1.VOUCHERPHYSICAL = T3.VOUCHER
AND (T1.DATAAREAID = T3.DATAAREAID)
AND (T1.PARTITION = T3.PARTITION)
)
)
AND (
T1.DATEPHYSICAL = T3.TRANSDATE
AND (T1.DATAAREAID = T3.DATAAREAID)
AND (T1.PARTITION = T3.PARTITION)
)
)
AND (
T1.INVENTTRANSORIGIN = T3.INVENTTRANSORIGIN
AND (T2.DATAAREAID = T3.DATAAREAID)
AND (T2.PARTITION = T3.PARTITION)
)
) and t3.INVENTTRANSPOSTINGTYPE in (0)
LEFT JOIN INVENTDIM t4 ON (
t4.inventdimid = t1.inventdimid
AND t4.PARTITION = t1.PARTITION
AND t4.dataareaid = t1.dataareaid
)
LEFT OUTER JOIN INVENTTABLEMODULE T19 ON T19.ItemID = T1.ItemID AND T19.DataAreaID = T1.DataAreaID and T19.Partition = T1.Partition AND T19.MODULETYPE=0
LEFT OUTER JOIN INVENTTABLE T20 ON T1.ITEMID = T20.ITEMID AND T1.DATAAREAID = T20.DATAAREAID
where T20.ITEMTYPE <> 2
Any help would be greatly appreciated.

Want title on TOP from Oracle query

With the below query I generate a datable whose diagram is as below:-
SELECT *
FROM (SELECT DISTINCT sv.mkey, vehicle_no,
CASE
WHEN sv.audit_flag = 'N'
THEN 'REJECTED'
ELSE 'PENDING APPROVAL'
END isnullcheck,
TO_CHAR (date_in,
'dd-MM-yyyy'
)
|| ' & '
|| time_in vehicleindate_time,
TO_CHAR (date_out,
'dd-MM-yyyy'
)
|| ' & '
|| time_out vehicleoutdate_time,
gate_no_in || ' & ' || gate_no_out ingate_outgateno,
remark_in remarkin, NULL receipt_no, date_in,
CASE
WHEN sv.audit_flag = 'N'
THEN 'Y'
ELSE 'N'
END hod
FROM xxcus.xxgid_audit_entry sv
WHERE sv.project_id = '1365'
AND (sv.audit_flag IS NULL OR sv.audit_flag = 'N')
UNION
SELECT NULL, NULL, 'PENDING APPROVAL', NULL, 'PENDING APPROVAL',
NULL, NULL, NULL, NULL, NULL
FROM DUAL
UNION
SELECT NULL, NULL, 'REJECTED', NULL, 'REJECTED', NULL, NULL, NULL,
NULL, NULL
FROM DUAL) qq
ORDER BY isnullcheck DESC
the generated datable is as below
[![Datatable][1]][1]
Now what, I want is.
The query will fetch result into two headings
ie. 1. REJECTED or 2. PENDING APPROVAL
but what happening here is it is going other than both the heading also. It should not go.
[![Image][2]][2]
Also see the html of grid
How to make that under two headings ?? is there any issue with query ?
Order by something else as well, and used NULLS FIRST on that:
ORDER BY isnullcheck DESC, mkey NULLS FIRST

SQL Server Count Occurrences of a value of colounns

Thank you for taking time to read this.
I have a ServiceDetails Table which have columns like
ID, ServiceID , ClientID... , Status ,IsFollowUp
and Services have
ID, Date , CityID, AreaID
Now when a service request is entered , its status is either 'pending', 'Completed','testing', or 'indeteriminent'.
Now end user wants a report that
City, Area , TotalServices , Total Completed without followup , Total Completed at First followup, Total Completed at 2nd followup ... , Total Completed at Fifth followup
I have Completed uptill now, Total Completed without followup but how do I calculate the Completed services followups count.
CREATE TABLE #TEMP#(
[ID] int PRIMARY KEY IDENTITY,
[Area] varchar(250),
[City] varchar(250),
[Total] int,
[WithoutFollowup] int,
[FirstFollowup] int,
[SecondFollowup] int,
[ThirdFollowup] int,
[FourthFollowup] int,
[FifthFollowup] int
);
DECLARE #AreaID AS bigint = 0
DECLARE #CityID AS bigint = 0
DECLARE #AreaName AS nvarchar(250) = ''
DECLARE #CityName AS nvarchar(250) = ''
DECLARE #VCCTDetailsID AS bigint = NULL, #ClientID AS bigint = NULL
,#TotalTests as int, #WithoutFollowup as int, #FirstFollowup as int,#SecondFollowup as int, #ThirdFollowup as int, #FourthFollowup as int, #FifthFollowup as int
,#Org as varchar(250),#City as varchar(250)
DECLARE cur CURSOR FOR
SELECT Areas.ID, Areas.Name, Cities.ID, Cities.CityName
FROM [dbo].[Areas]
INNER JOIN [dbo].[AreaCities] ON Areas.ID = AreaCities.AreaID
INNER JOIN [dbo].[Cities] ON AreaCities.CityID = Cities.ID
INNER JOIN [dbo].[States] ON States.ID = Cities.StateID
INNER JOIN [dbo].[Countries] ON Countries.ID = States.CountryID
WHERE [Areas].[IsActive] = 1
AND [Cities].[IsActive] = 1
AND [Areas].[CountryID] = 168
OPEN cur
FETCH NEXT FROM cur INTO #AreaID, #AreaName, #CityID, #CityName
WHILE ##FETCH_STATUS = 0
BEGIN
SET #Total = (
SELECT COUNT(1)
FROM [dbo].[ServiceDetails]
INNER JOIN [dbo].[Services] ON [ServiceDetails].[ServiceID] = [Services].[ID]
Where [ServiceDetails].[Status] !='Testing'
AND [ServiceDetails].[Status] !='Pending'
AND [Services].[AreaID] = #AreaID
AND [Services].[CityID] = #CityID
GROUP BY [Services].[AreaID],[Services].[CityID]
)
SET #WithoutFollowup = (
SELECT COUNT(1)
FROM [dbo].[ServiceDetails]
INNER JOIN [dbo].[Services] ON [ServiceDetails].[ServiceID] = [Services].[ID]
Where [ServiceDetails].[Status] !='completed'
AND [ServiceDetails].[IsFollowUp] = 'false'
AND [Services].[AreaID] = #AreaID
AND [Services].[CityID] = #CityID
GROUP BY [Services].[AreaID],[Services].[CityID]
)
SET #FirstFollowup = (
SELECT COUNT(1)
FROM [dbo].[ServiceDetails]
INNER JOIN [dbo].[Services] ON [ServiceDetails].[ServiceID] = [Services].[ID]
Where [ServiceDetails].[Status] !='completed'
AND [ServiceDetails].[IsFollowUp] = 'True'
GROUP BY [Services].[AreaID],[Services].[CityID]
)
INSERT #TEMP# ([Org],[City],[Total],[WithoutFollowup],[FirstFollowup],[SecondFollowup],[ThirdFollowup],[FourthFollowup],[FifthFollowup])
VALUES(#AreaName,#CityName,#Total,#WithoutFollowup,#FirstFollowup,#SecondFollowup,#ThirdFollowup,#FourthFollowup,#FifthFollowup);
FETCH NEXT FROM cur INTO #AreaID, #AreaName, #CityID, #CityName
END
CLOSE cur
DEALLOCATE cur
SELECT * FROM #TEMP#
DROP TABLE #TEMP#
I've accomplished this task using rownumbers and another temporary Table inside the cursor
INSERT INTO #Services#
SELECT ROW_NUMBER() OVER (ORDER BY [Services].[Date]) as 'RowNo',[ServiceDetails].* , [Services].[Date]
FROM [ServiceDetails]
INNER JOIN [Services] ON [Services].[ID] = [ServiceDetails].[VCCTsServiceID]
INNER JOIN [Clients] ON [Clients].[ID] = [ServiceDetails].[ClientID]
WHERE [Clients].[ID] LIKE #ClientID
ORDER BY [Services].[Date]
This #Services# is the exact replica of ServiceDetails table. Now we have all the services given to the client with rownumber and Date. It is sorted on date so we get the followups exactly when they are done. Now you can query what you want.
SET #TotalServices = ( SELECT COUNT(*) FROM #Services# )
SET #FirstSericeDate = (SELECT [#Services#].[Date] FROM #Services# WHERE [#Services#].[RowNo] = 1 )
SET #Status = (SELECT [#Services#].[Status] FROM #Services# WHERE [#Services#].[RowNo] = 1 )
SET #Date1 = (SELECT [#Services#].[Date] FROM #Services# WHERE [#Services#].[RowNo] = 2 )
SET #Status1 = (SELECT [#Services#].[Status] FROM #Services# WHERE [#Services#].[RowNo] = 2)
Then insert your variables into main temptable for reporting
INSERT #TEMP# ([RegNo], . . . [Status], Date1], [Status1] . .)
VALUES(#RegNo, . .. #Status, #Date1 , #Status1, . . );
TRUNCATE TABLE #Services#
FETCH NEXT FROM cur INTO #RegNo

Convert native sql query in Symfony2 query builder ( with select in join )

i have this ( huge ) sql query to convert into doctrine2 .
i already succeeded with createNativeQuery() but sometimes results don't match original one ( from mysql )
here is the query :
SELECT e1_.etapes AS etapes3, e1_.position AS position4, c0_.exercicesData_id AS Exercice_id, exo.titre as Exo, age.bornInf as ageInf, age.bornSup as ageSup, imc.bornInf as imcInf, imc.bornSup as imcSup, sexe.bornInf as sexeInf, sexe.bornSup as sexeSup
FROM ContrainteData c0_
LEFT JOIN ExerciceData e1_ ON c0_.exercicesData_id = e1_.id
LEFT JOIN Exercice exo ON e1_.exercice_id = exo.id
LEFT JOIN contraintedata_entrydata c3_ ON c0_.id = c3_.contraintedata_id
INNER JOIN (SELECT * FROM `entrydata` GROUP BY type_id, bornInf, bornSup) AS age ON age.type_id = 1
INNER JOIN (SELECT * FROM `entrydata` GROUP BY type_id, bornInf, bornSup) AS imc ON imc.type_id = 4
INNER JOIN (SELECT * FROM `entrydata` GROUP BY type_id, bornInf, bornSup) AS sexe ON sexe.type_id = 5
WHERE
( age.bornSup >= 30 and age.bornInf <= 30 ) and
( imc.bornSup >= 20 and imc.bornInf <= 20 ) and
( sexe.bornSup >= 1 and sexe.bornInf <= 1 ) and
e1_.entrainement_id = 6
GROUP BY etapes3, position4
ORDER BY etapes3 ASC, position4 ASC
with the queryBuilder , i have done the following :
$qb1 = $this->createQueryBuilder('c');
$qb2 = $this->createQueryBuilder('t');
$qb2->select( 't' )
->from ( 'bonk\AppBundle\Entity\EntryData', 'en' )
->groupBy( 'en.type')
->addGroupBy( 'en.bornInf' )
->addGroupBy( 'en.bornSup' );
$qb1->select( 'c' )
->leftJoin( 'c.exercicesData', 'e' )
->leftJoin( 'e.exercice' , 'ex' )
->join ( $qb2->getDql(), 'age', 'with', 'age.type = 1' )
->join ( $qb2->getQuery()->getDql(), 'imc', 'with', 'imc.type = 4' )
->join ( $qb2->getQuery()->getDql(), 'sexe', 'with', 'sexe.type = 5')
->where ( 'age.bornSup >= 30 and age.bornInf <= 30' )
->andWhere( 'imc.bornSup >= 20 and imc.bornInf <= 20' )
->andWhere( 'sexe.bornSup >= 1 and sexe.bornInf <= 1' )
->andWhere( 'e.entrainement = 6' )
->groupBy ( 'e.etapes', 'ASC' )
->addGroupBy( 'e.position', 'ASC' );
return $qb1->getQuery()->getArrayResult();
i have the following error :
"[Semantical Error] line 0, col 116 near 'SELECT t FROM': Error: Class 'SELECT' is not defined "
i finally succeed with a mysql view which is called by a fake entity in doctrine and DQL Query .
to create a view on sql , simply execute this line :
"create view VIEWNAME YOUQUERY"
in my example :
"create view entrydataView SELECT * FROM `entrydata` GROUP BY type_id, bornInf, bornSup"

Resources