Problem with group by 3 letters
I made a query and took all customers_from starting with first and grouped but my problem is that I want to do the same thing but on all the fields customers_from
For example, I have the following names in my fields:
1st_qwe, 1st_asd, 1st_ghj, 1st_poi, add_qwe, add_rtz, add_lkj, add_puz, poi_ghj, poi_gjhgj, poi_tgb etc...
So I'd like to take the three letter and condition like that
Code:
SELECT IF (customers_from LIKE '1st%','1rst',customers_from) AS Origin,
COUNT (cu.customers_id) AS effectif_vg
FROM en_customers cu INNER JOIN en_commands co on cu.customers_id = co.customers_id
WHERE customers_free ='1'
GROUP BY Origin"
Is there a solution to my problem?
Re: Problem with group by 3 letters
If you make a complaint in this:
SELECT
LEFT (cu.customers_from, 3) as origin,
COUNT (cu.customers_id) AS effectif_vg
FROM en_customers cu
INNER JOIN en_commands co on cu.customers_id = co.customers_id
WHERE ***co or cu ??? *** .customers_free = '1'
GROUP BY LEFT (cu.customers_from, 3)
Must not operate?
For against, I do not know what it is if you have customers_from who have a length <3, on MySQL, it still includes ...
Re: Problem with group by 3 letters
With Oracle and other DBMS, you can use substr (field, index_of_depart_starting_a_1, length), giving
SELECT substr (customers_from, 1, 3) as origin,
COUNT (cu.customers_id) AS effectif_vg
FROM en_customers cu INNER JOIN en_commands co on cu.customers_id = co.customers_id
WHERE customers_free ='1 '
GROUP BY Origin"
Re: Problem with group by 3 letters
Ok, the substr seems a little more generic, I'm used to left or right, in MySQL, you can make the 2 with the same result ...
Re: Problem with group by 3 letters
Thank you but my problem is that I wanted to see more of origin (which are not affected by the combination) but I think it's impossible.