Mysql WHERE子句不起作用?

时间:2017-10-17 04:43:11

标签: mysql

我在这里看过一堆文章,但我找不到我正在寻找的文章

SELECT SUM(adult) as adult_sold_1 WHERE showtime = '1'From tickets

这里的一切都有效,但当我尝试使用WHERE时,整个事情都停止了......

这有什么问题?

编辑:

还有办法一次做多个吗?

喜欢

SELECT SUM(adult) as adult_sold_1 From tickets WHERE showtime = '1' 

那么学生在成年人的位置也是一样吗?

3 个答案:

答案 0 :(得分:4)

您没有导致您出错的FROM(表格)

SELECT SUM(adult)as adult_sold_1 FROM TABLE_NAME WHERE showtime ='1'

答案 1 :(得分:0)

SELECT查询应该是:

SELECT `field_name` FROM `table_name`

有WHERE子句:

SELECT `field_name` FROM `table_name` WHERE `field_name` = 'some_value'

在您的查询中,FROM未写入&并没有妥善安置。应该是这样的:

SELECT SUM(`adult`) as adult_sold_1 FROM `tickets` WHERE `showtime` = '1'

SUM()语法:

SELECT SUM(`column_name`) FROM `table_name` WHERE condition;

多个SUM()示例:

前1: -

SELECT SUM(CASE WHEN `item` = 'ABC' THEN `price` END) as ABC_price,
    SUM(CASE WHEN `item` = 'XYZ' THEN `price` END) as XYZ_price
FROM `item_table`

Ex 2: -

SELECT SUM(`price`) as total_price, SUM(`quantity`) as total_quantity FROM `item_table`

答案 2 :(得分:0)

SELECT SUM(adult) as adult_sold_1 
From tickets
WHERE `showtime` = 1

如果您的showtime是整数,我认为它不需要' ' 如果您的showtime是字符串使用LIKE而不是=

WHERE `showtime` like '1'