how to predefine the items after a 'by' ?

Hi,

?

quite often we use the following syntax:

?

select count i , sum qty by exchange from mytable

?

can I force the exchange to be a list that I predefined? something like :

?

select count i , sum qty by NYSENASDAQ`BATS from mytable

?

does anyone know what’s the syntaxt?

?

thanks!


CHEN, Cheng

Not that I know of.
You could also resort like this if that’s your aim:

q)t

a b


1 8

2 1

1 9

2 5

3 4

2 6

3 6

q)(a:2 1 3)#select count i by a from t

a| x

-| -

2| 3

1| 2

3| 2

q)

Hi,

Is this what your looking for:

q)t:( sym:9?ab; qty:9?9;
exchange:9#NYSENASDAQBATSCMELSE)<br> q)t<br> sym qty exchange<br> ----------------<br> a 7 NYSE<br> a 6 NASDAQ<br> a 3 BATS<br> b 4 CME<br> a 3 LSE<br> a 4 NYSE<br> b 8 NASDAQ<br> a 4 BATS<br> b 6 CME<br> <br> </tt><tt>/ our selected list</tt> <tt>q)l:NYSENASDAQBATS



/ select only those in our list l

q)select count i , sum qty by exchange from t where exchange in
l

exchange| x qty

--------| -----

BATS | 2 7

NASDAQ | 2 14

NYSE | 2 11



/ select grouping by our list l

q)select count i , sum qty by exchange in l from t

l| x qty

-| -----

0| 3 13

1| 6 32

q)



/ custom groupings using dictionary

q)d:(NYSENASDAQBATSLSE!AABB)

q)d

NYSE | A

NASDAQ| A

BATS | B

LSE | B

q)select count i , sum qty by `other^d[exchange] from t

exchange| x qty

--------| -----

A | 4 25

B | 3 10

other | 2 10




Regards,
Ryan Hamilton

On 4/10/2013 9:01 PM, CHEN, Cheng wrote:

Hi,

 

quite often we use the following syntax:

 

select count i , sum qty by exchange from mytable

 

can I force the exchange to be a list that I predefined? something like :

 

select count i , sum qty by NYSENASDAQ`BATS from mytable

 

does anyone know what’s the syntaxt?

 

thanks!


CHEN, Cheng


You received this message because you are subscribed to the Google Groups “Kdb+ Personal Developers” group.
To unsubscribe from this group and stop receiving emails from it, send an email to personal-kdbplus+unsubscribe@googlegroups.com.
To post to this group, send email to personal-kdbplus@googlegroups.com.
Visit this group at http://groups.google.com/group/personal-kdbplus?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

-- 

TimeStored.com - KDB+ Training, Consulting, Software