how to compare value of a row in a table with sum of colum in another table in sql

时间:2017-03-02 23:30:43

标签: php mysql sql database

I have to tables, i want to select all from table1 where amount is less than the sum of a column in table2.

Please how do i do this in sql.

2 个答案:

答案 0 :(得分:0)

Not Tested. Just scribbled something in Notepad. Please try this -

SELECT *
FROM table1
WHERE table1.amount < (SELECT SUM(column2) FROM table2)

答案 1 :(得分:0)

希望这有效:

Collecting multiprocessing
Using cached multiprocessing-2.6.2.1.tar.gz
Complete output from command python setup.py egg_info:
Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "/private/var/folders/7s/sswmssj51p73hky4mkqs4_zc0000gn/T/pip-build-8c0dk6ai/multiprocessing/setup.py", line 94
    print 'Macros:'
                  ^
SyntaxError: Missing parentheses in call to 'print'

----------------------------------------
Command "python setup.py egg_info" failed with error code 1 in /private/var/folders/7s/sswmssj51p73hky4mkqs4_zc0000gn/T/pip-build-8c0dk6ai/multiprocessing/