mysql - I would like to count stocks that have price of 0 or null -


i have these 2 tables:

table1: stock_list

stock_name  year    qty reserve stock1  2015    1   0 stock1  2016    1   1 stock1  2016    1   0 stock1  2016    1   0 stock2  2015    1   0 stock2  2015    1   0 stock2  2015    1   0 stock2  2016    1   1 stock2  2016    1   1 stock2  2016    1   0 

the second table is: products

variant  list_price stock1  2015    2000 stock1  2016    0 stock2  2015    3000 stock2  2016    null stock3  2016    4000 

the result looking table:

name    year    qty reserved    list_price stock1  2016    3   1   0 stock2  2016    3   2   null 

is there way reach result 1 mysql statement.

try:

    select s.stock_name name, s.year, sum(s.qty) qty, sum(s.reserved) reserve, p.list_price     stock_list s inner join products p     on s.stock_name=p.variant , s.year=p.my     p.list_price=0 or p.list_price null     group s.stock_name, s.year, p.list_price 

Comments

Popular posts from this blog

php - Wordpress website dashboard page or post editor content is not showing but front end data is showing properly -

javascript - Get parameter of GET request -

javascript - Twitter Bootstrap - how to add some more margin between tooltip popup and element -