Ich habe Probleme, diese SQL-Abfrage in eine SQL-Abfrage Alchemy Umwandlung:SQL Alchemy Join-Anweisung
query = """
SELECT i.case_num,
to_char(i.date_time, 'FMMonth FMDD, YYYY'),
to_char(i.date_time, 'HH24:MI'),
i.incident_type,
i.incident_cat,
i.injury,
i.property_damage,
i.description,
i.root_cause,
a.corrective_action,
a.due_date,
i.user_id
FROM incident as i, action_items as a
WHERE i.case_num = a.case_id AND i.case_num = %s;
"""
Ich habe versucht, die folgenden aber haben nichts als Fehler erhalten:
sqlalchemy.orm.exc .NoResultFound: Es wurde keine Zeile für einen() gefunden
results = dbsession.query(Incidents.case_num,
func.to_char(Incidents.date_time, 'FMMonth FMDD, YYYY'),
func.to_char(Incidents.date_time, 'HH24:MI'),
Incidents.incident_type,
Incidents.incident_cat,
Incidents.injury,
Incidents.property_damage,
Incidents.description,
Incidents.root_cause,
Actions.corrective_action,
Actions.due_date,
Incidents.user_id).join(Actions).filter_by(case_id = id).one()
Attribute: Mapper
results = dbsession.query(Incidents.case_num,
func.to_char(Incidents.date_time, 'FMMonth FMDD, YYYY'),
func.to_char(Incidents.date_time, 'HH24:MI'),
Incidents.incident_type,
Incidents.incident_cat,
Incidents.injury,
Incidents.property_damage,
Incidents.description,
Incidents.root_cause,
Incidents.user_id).join(Actions.corrective_action, Actions.due_date).filter_by(case_id = id).one()
Ich glaube, ich kann zwei separate Abfragen durchführen, würde aber lieber herausfinden, wie man eine Join-Abfrage durchführt.
Was angezeigt wird, wenn Sie Zeichenfolge Darstellung von Ihnen drucken r Frage (sagen wir, die erste)? – erhesto
Nichts, also glaube ich nicht, dass die Abfrage richtig formatiert ist. – JTP709
Was meinst du mit nichts? Wird das Drucken durch eine Ausnahme unterbrochen oder ist das Ergebnis eine leere Zeichenfolge? – erhesto