Insert into table values(42,'stuff');
Insert into table (col2,col1) values('stuff',42)
insert into animals values ('wibble','opossum','2014-11-14');
insert into animals (name,species,birthdate) values ('wibble','opossum','2014-11-14')
# Find the names of the individual animals that eat fish.
# The animals table has columns (name, species, birthdate) for each individual.
# The diet table has columns (species, food) for each food that a species eats.
QUERY = '''
select animals.name
from animals join diet on animals.species=diet.species
where food='fish'
'''
another question:
Which species does the zoo have only one of?
wrong way: select species,count(*) as num from animals group by species where num=1;
REMEMBER :The value of num come from count and group by.But where always runs before aggregations
BECAUSE: There's no num column in the animals table.And you can't use where after a group by anyway.(而且你不能在 group by 后面使用where) If you tried this query out,you'd get a big error ,but if we change just one word,we can make this right,whereas where filters(筛选) the source table,animals,having filters the result table.So having applies after the group BI aggregation.
转载于:https://my.oschina.net/Bettyty/blog/757874