Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
Author |
Topic |
iwahyudi
Starting Member
11 Posts |
Posted - 2013-02-07 : 07:29:08
|
Hai , Newbie in sql please help me to how to result this data:Brand_name Red Black Green blueHonda 2 1 - -Suzuki - - - -Yamaha 1 - - 1Kawasaki - - 1 -And i have data table like thisTable_Brand Dealer_id Brand_NameH001 HondaH002 HondaY001 YamahaY002 YamahaK001 KawasakiS001 SuzukiTable_Transaction Dealer_id ColourH001 RedH001 RedH002 BlackY001 RedY002 BlueK001 GreenPlease help meIndra Wahyudi |
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2013-02-07 : 09:39:52
|
[code]SELECT Brand_Name,[Red],[Black],[Blue],[Green]FROM(SELECT b.Brand_Name, t.ColourFROM Table_Brand bINNER JOIN Table_Transaction tON t.Dealer_id = b.Dealer_id)rPIVOT (COUNT(1) FOR Colour IN ([Red],[Black],[Blue],[Green]))p[/code]------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
|
|
iwahyudi
Starting Member
11 Posts |
Posted - 2013-02-07 : 23:15:07
|
Thx U Visakh16.....Indra Wahyudi |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2013-02-08 : 03:33:11
|
welcome------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
|
iwahyudi
Starting Member
11 Posts |
Posted - 2013-02-14 : 04:35:46
|
Hai..Sorry Need Help again How to join this query into one table ..query like this :select sum(ots_principal) as tot_ar from WOM_AGING.XAGING_MONTHLY where periode = 201212select count(order_no) as tot_count from WOM_AGING.XAGING_MONTHLY where periode = 201212select distinct b.cabang_data_audit as cabang, (case when a.dpd = 0 then '1 DPD 0' when a.dpd <= 30 then '2 DPD 01-30' when a.dpd <= 60 then '3 DPD 31-60' when a.dpd <= 90 then '4 DPD 61-90' when a.dpd <= 120 then '5 DPD 91-120' when a.dpd <= 150 then '6 DPD 121-150' when a.dpd <= 180 then '7 DPD 151-180' when a.dpd > 180 then '8 DPD 180 up' else '9 tdk ada data 'end )bucketfrom WOM_AGING.XAGING_MONTHLY a,WOM_AUDIT.SWI_CABANG_MAP_AUDIT b where a.cab_id =b.cab_id and a.periode= 201212 group by cabang_data_audit Ps: for Field Cabang and Buket already succes but Tot_ar an tot_count not yet because always error message The result must like this :Cabang Buket Tot_Ar Tot_CountBest RgsIndraIndra Wahyudi |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2013-02-14 : 10:06:35
|
so do you want cummulate figures for other two fields (Tot_Ar Tot_Count) without splitting based on others------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
|
|
iwahyudi
Starting Member
11 Posts |
Posted - 2013-02-14 : 10:21:12
|
Yes Visakh16 without splitThe result must like this :Cabang Bucket Tot_Ar Tot_CountBut I success for Cabang and Bucket but other not yet how to join that into one table??thxIndra Wahyudi |
|
|
|
|
|
|
|