2016-09-07 4 views
0

Ich habe eine Tabelle, die zwei Felder Menge und Preis hat, ich beide Felder Wert multiplizieren soll: hier ist das, was ich will, was möglich ist, mit MYSQLWie abfragen multiplizieren 2 Zelle für jede Zeile mit Realm?

Quantity| Price | Total 

6  | 2 | null // should be 12 
2  | 10 | null // should be 20 

Vor Verwendung werden kann getan

SELECT 
    quantity, Price, 
    quantity* Price as 'Total' 
FROM myTable 

Ich möchte das gleiche Ergebnis mit Realm-Abfrage .. Wie kann ich das erreichen .. Jede Hilfe wird geschätzt .. Vielen Dank.

+0

welche Plattform unterstützt? Android oder Swift oder React-Native oder ...? – EpicPandaForce

+0

für Android .... –

Antwort

0

Mit Realm für Android müssen Sie ein neues Feld und benutzerdefinierte Setter hinzufügen.

Diese Lösung 0.88.0+

public class Something extends RealmObject { 
    private long quantity; 
    private long price; 
    private long total; 

    public long getQuantity() { 
     return quantity; 
    } 

    public long getPrice() { 
     return price; 
    } 

    public long getTotal() { 
     return total; 
    } 

    public void setQuantity(long quantity) { 
     this.quantity = quantity; 
     this.total = this.quantity * this price; 
    } 

    public void setPrice(long price) { 
     this.price = price; 
     this.total = this.quantity * this.price; 
    } 

    public void setTotal(long total) { // preferably don't use 
     this.total = total; 
    } 
} 
+0

Dieses Problem ist sehr ähnlich zu [dieser Github Hilfe Ausgabe] (https://github.com/realm/realm-java/issues/3378) – EpicPandaForce

+0

Vielen Dank @EpicPandaForce –

+0

Whoops ich multipliziert mit insgesamt statt Preis. Es wurde jedoch behoben – EpicPandaForce

Verwandte Themen