| |
|
If this is your first visit, be sure to check out the FAQ by clicking the link above.
You may have to register before you can post: click the register link above to proceed.
To start viewing messages, select the forum that you want to visit from the selection below.
|
 |

03-17-11, 08:04
|
|
Registered User
|
|
Join Date: Dec 2008
Location: Netherlands
Posts: 56
|
|
|
GROUP BY with if/else
|
|
I have this group statement:
GROUP BY calc_inh.kwaliteit_id, calc_id.kwaliteit_id_std, calc_inh.dikte
What I need is the next statement but I don't know how to achive this in onlly one query:
If calc_inh.kwaliteit_id > 0
GROUP BY calc_inh.kwaliteit_id, calc_inh.dikte
else
GROUP BY calc_id.kwaliteit_id_std, calc_inh.dikte
Any ideas?
|
|

03-17-11, 09:02
|
|
Registered User
|
|
Join Date: Sep 2009
Location: San Sebastian, Spain
Posts: 623
|
|
Hi,
your question is a little vague. I think what you are looking for here is a change in the group by depending on some value. Where is that value coming from? It might be better to provide the table definitions and the full query?
|
|

03-17-11, 09:21
|
|
Registered User
|
|
Join Date: Dec 2008
Location: Netherlands
Posts: 56
|
|
|
|
Quote:
Originally Posted by it-iss.com
Hi,I think what you are looking for here is a change in the group by depending on some value.
|
Correct.
Quote:
Originally Posted by it-iss.com
Where is that value coming from?
|
From my database
Quote:
Originally Posted by it-iss.com
It might be better to provide the table definitions and the full query?
|
Code:
$sql_i = "SELECT
calc_id.id AS id,
calc_id.naam AS naam,
calc_inh.pos AS pos,
calc_id.naam_in_pos AS naam_in_pos,
calc_id.kwaliteit_id_std AS kwaliteit_id_std,
calc_id.attest_std AS attest_std,
calc_inh.aantal AS aantal,
calc_inh.lengte AS lengte,
calc_inh.breedte AS breedte,
calc_inh.dikte AS dikte,
calc_inh.kwaliteit_id AS kwaliteit_id,
calc_inh.gewicht_stk AS gewicht_stk,
omtr.omschrijving AS soort
FROM offerte_inh AS inh
LEFT JOIN calculatie_id AS calc_id
ON calc_id.id = inh.calculatie_id
LEFT JOIN calculatie_inh AS calc_inh
ON calc_inh.id_calculatie = calc_id.id
LEFT JOIN calculatie_omtrek AS omtr
ON omtr.id = calc_inh.soort_id
WHERE inh.offerte_id = '".$row['id']."'
GROUP BY calc_inh.kwaliteit_id, calc_id.kwaliteit_id_std, calc_inh.dikte
ORDER BY calc_inh.id ASC ";
I hope you can help me out?
|
|

03-17-11, 09:45
|
|
Registered User
|
|
Join Date: Sep 2009
Location: San Sebastian, Spain
Posts: 623
|
|
Code:
SELECT calc_id.id AS id,
calc_id.naam AS naam,
calc_inh.pos AS pos,
calc_id.naam_in_pos AS naam_in_pos,
calc_id.kwaliteit_id_std AS kwaliteit_id_std,
calc_id.attest_std AS attest_std,
calc_inh.aantal AS aantal,
calc_inh.lengte AS lengte,
calc_inh.breedte AS breedte,
calc_inh.dikte AS dikte,
calc_inh.kwaliteit_id AS kwaliteit_id,
calc_inh.gewicht_stk AS gewicht_stk,
omtr.omschrijving AS soort
FROM offerte_inh AS inh
LEFT JOIN calculatie_id AS calc_id
ON calc_id.id = inh.calculatie_id
LEFT JOIN calculatie_inh AS calc_inh
ON calc_inh.id_calculatie = calc_id.id
LEFT JOIN calculatie_omtrek AS omtr
ON omtr.id = calc_inh.soort_id
WHERE inh.offerte_id = 'info'
GROUP BY IF(calc_inh.kwaliteit_id >
0, calc_inh.kwaliteit_id, calc_inh.kwaliteit_id_std),
calc_inh.dikte
ORDER BY calc_inh.id ASC
|
|

03-22-11, 05:49
|
|
Registered User
|
|
Join Date: Dec 2008
Location: Netherlands
Posts: 56
|
|
Thanks for helping me out Ronan!
|
|
| Thread Tools |
Search this Thread |
|
|
|
| Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|