Kaskus

Tech

andhydbAvatar border
TS
andhydb
[ask] query
gan, mau tanya mengenai query
tabel barang:
+----+---------+---------------+--------+
| id | item_id | property_name | value |
+----+---------+---------------+--------+
| 1 | 1 | color | blue |
| 2 | 1 | size | large |
| 3 | 1 | weight | 65 |
| 4 | 2 | color | orange |
| 5 | 2 | weight | 57 |
| 6 | 2 | size | large |
| 7 | 3 | size | small |
| 8 | 3 | color | red |
| 9 | 3 | weight | 12 |
| 10 | 4 | color | violet |
| 11 | 4 | size | medium |
| 12 | 4 | weight | 34 |
| 13 | 5 | color | green |
| 14 | 5 | weight | 10 |
+----+---------+---------------+--------+

=> data tabel tersebt mau ditampilkan sperti dibawah ini:

+---------+--------+--------+--------+
| item_id | color | size | weight |
+---------+--------+--------+--------+
| 1 | blue | large | 65 |
| 2 | orange | large | 57 |
| 3 | red | small | 12 |
| 4 | violet | medium | 34 |
| 5 | green | NULL | 10 |
+---------+--------+--------+--------+

cb pake query :

SELECT item_id,
IF(property_name='color',value,NULL) AS color,
IF(property_name='size',value,NULL) AS size,
IF(property_name='weight',value,NULL) AS weight
FROM properties
GROUP BY item_id

eh , tampilan datanya seperti dbawah ini, gk sesuai yg d atas.

item_id color size weight
1 blue NULL NULL
2 orange NULL NULL
3 NULL small NULL
4 violet NULL NULL
5 green NULL NULL

ada yg tau query -nya ngga, biar data yg ditampikan sesuai prmintaan??
trims........
0
544
2
GuestAvatar border
Komentar yang asik ya
Urutan
Terbaru
Terlama
GuestAvatar border
Komentar yang asik ya
Komunitas Pilihan