I have five tables in my db mysql: tbl_A, tbl_b, tbl_C, tbl_D and tbl_E and I execute this four query:
SELECT COUNT(idDTES) AS stridDTES
, SUM(CL_BT_DIS) AS strCL_BT_DIS
, SUM(AV) AS strAV
, COUNT(SC) AS strL
, COUNT(idDTES) - COUNT(SC) AS strB
FROM tbl_A
GROUP BY DATE_E
***************
SELECT SUM(Rif_AV) AS strRif_AV
, SUM(Rif_n_CL) AS strRif_n_CL
FROM tbl_B
***************
SELECT SUM(tbl_C.cl_BT) AS strCl_BT
, COUNT(tbl_D.EVENT) AS strEVENT
FROM tbl_C
INNER JOIN tbl_D ON tbl_D.LINE = tbl_C.COD_LINE
GROUP BY DATE_E
***************
SELECT SUM(N_S_TR) AS strNSTR FROM tbl_E GROUP BY DATE_E
There is possible to have same output with only query combining the four queries?
Any help would be very much appreciated and many thanks to any who can help me.
You’re grouping by DATA_E, but that field isn’t in the select. There isn’t any field in the select, just sums and counts. So how many rows does this query return?
And how do you know what each row contains if you don’t select some identifying field as well (for example DATA_E)?
I have JOIN queries 1 and 2 and new query working, but I don’t see for queries 3 and 4…:
SELECT
COUNT(A.idDTES) AS stridDTES
, SUM(A.CL_BT_DIS) AS strCL_BT_DIS
, SUM(A.AV) AS strAV
, COUNT(A.SC) AS strL
, COUNT(A.idDTES) - COUNT(A.SC) AS strB
, SUM(CA.Rif_AV) AS strRif_AV
, SUM(CA.Rif_n_CL) AS strRif_n_CL
FROM
tbl_A A INNER JOIN tbl_B CA ON A.idDTES = CA.DM
GROUP BY DATA_E
If you want to union theese results, you should change your selected columns for all queries so their count will be the same (if you select 3 columns from first table, you should select 3 from second and third as well)