.. _parameter-anchor:
Parameter Types
===============
The SDQL data types are:
* Number (points, first downs, home runs, etc.)
* String (team, division, conference, etc.)
* List (quarter scores, inning runs, umpires, etc.)
* Date (date)
* Line (MLB line, run line, etc.)
number
------
SDQL database numbers are Python integers and Python floats.
Number parameters can be combined using the usual math symbols: +, -, / and * (for multiplication).
To see the date and team name for NFL teams after they had more than 10 yards per pass, use the SDQL:
`date, team @ p:passing yards > 10 * p:passes `_.
string
-------
Database strings have all of the expected properties of Python strings.
To find all NBA team names that do not end in an *s*, use the SDQL:
`Unique(team) @ team[-1] != 's' `_.
To find all MLB teams with a two-word name, use the SDQL:
`U(team) @ len(team.split()) = 2 `_
*Unique* (abbreviated *U*) is an example of an SDQL summative (see :ref:`summative-anchor`) and *len* is a Python built-in.
list
-----
Database lists have all of the expected properties of Python lists.
The contents of lists are accessed by offset (starting at 0) using square brackets.
To see the date, team and opponent for MLB teams that scored five runs in the first inning, use the SDQL:
`date, team, o:team @ inning runs[0] = 5 `_.
The list indexing starts at *0*, so *inning runs[0]* gives runs in the first inning and *inning runs[8]* gives runs in the ninth inning.
To see the date, team and opponent for MLB teams that scored a total of ten runs in the first three innings, use the SDQL:
`date, team, o:team @ sum(inning runs[:3]) = 10 `_.
*sum* is a Python built-in method and used here to add up the first three values of the *inning runs* list.
To see the date, team, final score *in the game after* an MLB team scored two runs in each of the 5th, 6th and 7th innings, use the SDQL:
`date, team, o:team, Column((runs,o:runs),format='%d-%d') as 'Final'@ p:inning runs[4:7] = [2,2,2] `_ .
The SDQL summative *Column* (see :ref:`summative-anchor`) is called explicitly in order to format the *Final* score.
Pythonic list splicing works both ways: to find non-extra inning MLB games in which the team scored one run in each of the last four innings, use the SDQL:
`date, team @ inning runs[-4:] = [1,1,1,1] and len(inning runs)=9 `_.
To isolate teams that scored at least 4 runs in each of at least 3 innings, use Python's anonymous function *lambda* along with built-ins *sum* and *map*:
`sum(map(lambda r:r>=4,inning runs))>=3 `_
The same query can also be done with Python built-ins *len* and *filter*:
`len(filter(lambda r:r>=4,inning runs))>=3 `_
date
----
The date parameter has its own type to allow convenient addition and subtraction.
A date minus a date is a number while a date plus or minus a number is a date.
To see how NBA teams have performed when looking ahead to at least three days off, use the SDQL:
`S(points>o:points) as 'Wins',S(points 3 `_.
To see how NFL teams have done against the line when they have more than a week of rest, use the SDQL:
`S(points+line>o:points) as 'ATS Wins',S(points+line 7 `_.
The SDQL built-in variable *today* is of type date.
To see the Lakers' games for next week, use the SDQL:
`today < date < today + 7 and team=Lakers `_
line
----
Money line parameters have their own type to allow queries on line differences.
To request the average runs scored and runs allowed for MLB teams when they are exactly 50 cents more favored than in their previous game, use the SDQL:
`A(t:runs), A(o:runs) @ t:line - p:line = -50 `_.
This query covers favorite to bigger favorite (e.g. p:line = -120 and line = -170), dog to favorite (e.g. p:line = 120 and line = -130), and dog to less of a dog (e.g. p:line = 180 and line = 130).