简体   繁体   中英

Compare two numeric columns between tables in sql

Hi I would like to create a ms sql query two numeric columns (Days Consumed and vs limit day) between tables in ms sql here are my tables...

Table 1

Days consumed   case_id       case_deficiency 
1               101           Debris 
5               102           Graffiti
1               103           Not Functioning

on Second table I have

Table 1

id     limit day     case_deficiency
1      1             Debris
2      3             Graffiti
3      1             Not Functioning

I would like to view/show all case_deficiency if already exceeded the limit day.. in this case Graffiti already exceeded the DAY Consumed > Limit day. Hoping for your helping hand on this situation. Thanks

It looks like you want to link the tables based on case_deficiency . The rest is just an appropriate join . So:

select t1.*
from table1 t1 join
     table2 t2
     on t1.case_deficiency = t2.case_deficiency
where t2.limitday < t1.daysconsumed;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM