简体   繁体   English

SQL Count Case NOT COUNT multiple strings

[英]SQL Count Case NOT COUNT multiple strings

I am having issues with an assignments for school.我的学校作业有问题。 I need to seperate the tweets of Donald Trump.我需要将唐纳德特朗普的推文分开。 I need to get seperate columns.我需要单独的列。 I got the 3 first to work.我得到了3个第一个工作。 But the last one where it needs to be neither of the first 3. But keep getting issues.但是最后一个不需要前三个。但不断遇到问题。

SELECT 
    COUNT(CASE WHEN software LIKE '%iPhone%' THEN 1 END) AS 'Tweets from iPhone',
    COUNT(CASE WHEN software LIKE '%Android%' THEN 1 END) AS 'Tweets from Android',
    COUNT(CASE WHEN software LIKE '%Web Client%' THEN 1 END) AS 'Tweets from Web Client',
    COUNT(CASE WHEN software NOT LIKE ('%Web Client%' OR '%iPhone%' OR '%Android%') THEN 1 END) AS 'Tweets from other Platforms'
FROM tt2

Hope I can get some help with this issue:)希望我能在这个问题上得到一些帮助:)

NOT LIKE doesn't take a list. NOT LIKE不带列表。 You need to use separate conditions:您需要使用单独的条件:

COUNT(CASE WHEN software NOT LIKE '%Web Client%' AND software NOT LIKE '%iPhone%' AND software NOT LIKE '%Android%' THEN 1 END) AS TweetsfromotherPlatforms

You might be able to use regular expressions for this comparison.您可以使用正则表达式进行此比较。 But that depends on your database.但这取决于您的数据库。

Don't use single quotes for column names -- even if your database allows it.不要在列名中使用单引号——即使您的数据库允许这样做。 It is just confusing mixing up identifiers and strings.混淆标识符和字符串只是混淆。 Only use single quotes for date and string constants.仅对日期和字符串常量使用单引号。 The best advice is to name things so no escaping is necessary.最好的建议是命名事物,因此不需要 escaping。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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