Mit Sammlungen den Überblick behalten
Sie können Inhalte basierend auf Ihren Einstellungen speichern und kategorisieren.
Verwenden Sie NULLIF, um einen bestimmten Wert in Ihren Daten selektiv durch NULL zu ersetzen. Dies kann in Situationen hilfreich sein, in denen ein bestimmter Wert für fehlende oder ungültige Daten steht und Sie ihn zur weiteren Analyse oder Verarbeitung explizit als NULL markieren möchten.
Verwendungsbeispiel
Ersetzen Sie „-1“ im Feld Rabatt durch NULL.
NULLIF(Discount, -1)
Syntax
NULLIF( input_expression, expression_to_match )
Parameter
input_expression
Der Ausdruck, der ausgewertet werden soll. Sie können jeden gültigen Ausdruck als input_expression verwenden.
expression_to_match
NULLIF vergleicht expression_to_match mit input_expression. Wenn beide Werte gleich sind, gibt NULLIF NULL zurück, andernfalls input_expression. Sie können jeden gültigen Ausdruck als expression_to_match verwenden.
Beispiel
Angenommen, Sie möchten den durchschnittlichen Rabatt für Ihre Kunden berechnen. In Ihrer Anwendung ist „ohne Rabatt“ durch „-1“ repräsentiert. Die Formel AVG(Discount) berücksichtigt „-1“ und gibt ein falsches Ergebnis zurück. Sie können das vermeiden, indem Sie diese „-1“ in NULL-Werte konvertieren. Erstellen Sie dazu ein neues Feld mit dem Namen Rabatt mit NULL-Werten :
NULLIF(Discount, -1)
Diese Formel lässt sich so beschreiben: „Wenn das Feld Rabatt -1 ist, wird NULL zurückgegeben, andernfalls Rabatt.“
Sie können nun den durchschnittlichen Rabatt berechnen und dabei Bestellungen ohne Rabatt ausschließen:
[[["Leicht verständlich","easyToUnderstand","thumb-up"],["Mein Problem wurde gelöst","solvedMyProblem","thumb-up"],["Sonstiges","otherUp","thumb-up"]],[["Schwer verständlich","hardToUnderstand","thumb-down"],["Informationen oder Beispielcode falsch","incorrectInformationOrSampleCode","thumb-down"],["Benötigte Informationen/Beispiele nicht gefunden","missingTheInformationSamplesINeed","thumb-down"],["Problem mit der Übersetzung","translationIssue","thumb-down"],["Sonstiges","otherDown","thumb-down"]],["Zuletzt aktualisiert: 2025-07-31 (UTC)."],[],[],null,["# NULLIF\n\nUse `NULLIF` to selectively replace a specific value in your data with NULL. This can be helpful in situations where a particular value represents missing or invalid data, and you want to explicitly mark it as NULL for further analysis or processing.\n\nSample usage\n------------\n\nReplace -1 in the **Discount** field with NULL.\n\n`NULLIF(Discount, -1)`\n\nSyntax\n------\n\n`NULLIF( `\u003cvar translate=\"no\"\u003einput_expression\u003c/var\u003e`, `\u003cvar translate=\"no\"\u003eexpression_to_match\u003c/var\u003e` )`\n\n### Parameters\n\n#### input_expression\n\nThe expression to evaluate. You can use any valid expression as the \u003cvar translate=\"no\"\u003einput_expression\u003c/var\u003e.\n\n#### expression_to_match\n\n`NULLIF` compares \u003cvar translate=\"no\"\u003eexpression_to_match\u003c/var\u003e to \u003cvar translate=\"no\"\u003einput_expression\u003c/var\u003e. If the two are equal, `NULLIF` returns null, otherwise it returns the \u003cvar translate=\"no\"\u003einput_expression\u003c/var\u003e. You can use any valid expression as the \u003cvar translate=\"no\"\u003eexpression_to_match\u003c/var\u003e.\n\nExample\n-------\n\nSuppose you want to calculate the average discount given to your customers. Your application represents \"no discount\" as -1. The formula `AVG(Discount)` will count -1 and return an incorrect result. To avoid this, you can convert those -1s to NULLS. To do this, create a new field called, for example, **Discount With Nulls** :\n\n`NULLIF(`**`Discount`** `, -1)`\n\nThis formula can be read, \"If the **Discount** field is -1, return null, otherwise return **Discount**.\"\n\nYou can then calculate the average discount ignoring orders with no discount:\n\n`AVG(`**`Discount With Nulls`** `)`"]]