I have found the free version of TablePlus very useful to export csv data from my Home Assistant states and events tables. I used Postgresql as my database for HA, however this tool will query the native SQLite database of HA as well.
Query example to get whole house power usage for last two days, the SQL code may vary some for use with SQLite. Be gentle with your queries on the SQLite database of HA, if that is your default database, as it not as robust as other database. If you are going to experiment, first shutdown HA for a bit and copy the SQLite database to a test copy and then explore this copy of the data without effecting your HA running instance :
-- get SCE whole house power
WHERE (entity_id = 'sensor.home_instantaneous_demand'
AND last_updated > now() - interval '2 days')
-- sqlite interval example :