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 |
MrBloom
Starting Member
36 Posts |
Posted - 2013-04-30 : 11:51:13
|
ProductID date Weight Height Size1 04/08/1994 3.2 1 04/08/1994 43.51 04/08/1994 33.5 2 07/07/2000 67.92 07/07/2000 67.8 2 07/07/2000 8.2 Hi I have a table like the one above where the blanks are null. How Do I group by productID and date so that weight, height and size values are placed in one row where productID and date are same. As per the result below. Can't think how to do it. Thanks ProductID date Weight Height Size1 04/08/1994 3.2 33.5 43.52 07/07/2000 8.2 67.8 67.9 |
|
MrBloom
Starting Member
36 Posts |
Posted - 2013-04-30 : 11:54:05
|
Sorry the table above didn't come out well. See below... ProductID date Weight Height Size1 04/08/1994 3.2 null null1 04/08/1994 null null 43.51 04/08/1994 null 33.5 null2 07/07/2000 null null 67.92 07/07/2000 null 67.8 null2 07/07/2000 8.2 null nullHi I have a table like the one above where the blanks are null. How Do I group by productID and date so that weight, height and size values are placed in one row where productID and date are same. As per the result below. Can't think how to do it. Thanks ProductID date Weight Height Size1 04/08/1994 3.2 33.5 43.52 07/07/2000 8.2 67.8 67.9 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2013-05-02 : 02:03:49
|
if you're sure that you'll always have single set of values for Weight,Height and Size for a ProductID,date group you can use thisSELECT ProductID,[date],MAX(Weight) AS Weight,MAX(Height) AS Height,MAX(Size) AS SizeFROM TableGROUP BY ProductID,[date] ------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/https://www.facebook.com/VmBlogs |
|
|
|
|
|