d2jsp
Log InRegister
d2jsp Forums > Off-Topic > Computers & IT > Programming & Development > Mysql Query Help > Brainfart
Add Reply New Topic New Poll
Member
Posts: 2,246
Joined: Jul 23 2009
Gold: 13,860.85
Oct 17 2013 06:13pm
Hey guys,

This is the resultant query of:
`SELECT Size,Thickness, Type FROM Applications WHERE JobID=102`


I'm looking to be able to combine both of the `two` type returned rows into one single column as (Size * Thickness) such that the resulting query would show output of:

| - - - board_foot - - - | - - - type - - - |
| - - - 20 - - - - - - - - - | - - - two - - - -|
| - - - 49.5 - - - - - - - -| - - - half - - - |
Member
Posts: 32,925
Joined: Jul 23 2006
Gold: 3,804.50
Oct 17 2013 06:57pm
you want to use a group by.

select magical_function(size*thickness), type from applications
group by type

i'm not clear how you got 49.5, so replace magical_function with whatever computes the numbers you want. you may need a CASE statement (or whatever mysql's equivalent is) if the type impacts the calculation. i thought maybe the half meant double it, but then the "two" would mean half the 20 to make 10. which isn't the case. so maybe the fact that there are two rows means double it? dunno.

This post was edited by carteblanche on Oct 17 2013 07:01pm
Member
Posts: 2,246
Joined: Jul 23 2009
Gold: 13,860.85
Oct 17 2013 08:04pm
Quote (carteblanche @ Oct 17 2013 06:57pm)
you want to use a group by.

select magical_function(size*thickness), type from applications
group by type

i'm not clear how you got 49.5, so replace magical_function with whatever computes the numbers you want. you may need a CASE statement (or whatever mysql's equivalent is) if the type impacts the calculation. i thought maybe the half meant double it, but then the "two" would mean half the 20 to make 10. which isn't the case. so maybe the fact that there are two rows means double it? dunno.


Sorry if I came off unclear... I was going for grouping by the two 'half' values as in (15+10) * (.99+.99)
Thanks for the suggestion, ill start playing

Nevermind all I needed was your keyword, group by did the trick: SELECT SUM(Size)*SUM(Thickness), Type FROM Applications WHERE JobID=102 GROUP BY Type

Thanks

This post was edited by twixa on Oct 17 2013 08:08pm
Go Back To Programming & Development Topic List
Add Reply New Topic New Poll