A message from our CEO about the future of Stack Overflow and Stack Exchange. Read now.

New answers tagged

2

I can't be much help on the SQL front, but for VBA, I would recommend grouping your Dim statements, as it ultimately reduces compile time (scales well). For instance: Dim SelectClause As String Dim FromClause As String Dim WhereClause As String Dim OrderClause As String Dim FetchClause As String Becomes Dim SelectClause as String, ...


3

I think there's three big things you might be able to do to improve the performance of this. Write your query such that it doesn't need to execute the subquery for each line and/or have a HAVING clause by using an inner join which will automatically exclude those with no match. Use ST_Distance_Sphere(POINT(:longitude, :latitude), POINT(cities.longitude, ...


1

Yes, it is. For some reason you put everything upside-down: where you don't need a prepared statement (for a constant query) you are using it, but where a prepared statement is mandatory - for a query that uses variables - you don't. But I would say, it is not the main problem of this code. The main problem is this code being a total mess. There are two ...


2

You can use aggregation like this: select "Key", MAX(CASE WHEN "Is_Orig" = 1 THEN "Value" END) "Orig Value", MAX(CASE WHEN "Is_Prev" = 1 THEN "Value" END) "Prev Value", MAX(CASE WHEN "Is_Curr" = 1 THEN "Value" END) "Curr Value" from statistics group by "Key" The CASE statements select the value in each case and return NULL in the other cases. MAX ...


4

I'll answer your main questions: Can I refactor it so that the list of when like then statements occurs only once? (Preferably without complicating the code too much.) Yes, but not at the expense of complicating the code. In SEDE we unfortunately don't have the permission needed to create user-defined functions. I have introduced two concepts. One is a ...


3

Time constants Rather than writing tick_time_seconds = 300 you're better off using a more expressive built-in: from datetime import timedelta tick_time = timedelta(minutes=5) Unnecessary parens ...around this: line = ("################################################################################### \n") besides, you're better off writing line = ...


0

few comments: avoid data type float, unless you don't care about not accurate rounding. Solar_panel_rack, solar_panel and wind_turbine I would change structure:merge solar panel with solar_panel_rack if possible also would probably join wind turbine with solar panel_rack. It could potencialy have columsn like: ItemId, ItemTypeId(wind turbine or solar), ...


Top 50 recent answers are included