【優達學城測評】SQL-INSERT(9)
Insert into tablevalues(42,'stuff');
Insert into table (col2,col1)values('stuff',42)
insert into animalsvalues ('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 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 ha
wrong way:select species,count(*) as num from animals group by species where num=1;
REMEMBER :Thevalue 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