Thursday, February 17, 2022

Recent Questions - Stack Overflow

Recent Questions - Stack Overflow

Recent Questions - Stack Overflow


min and max of a column using another as tie breaker (postgres)

Posted: 17 Feb 2022 08:19 AM PST

We have a book table:

CREATE TABLE IF NOT EXISTS books(      title VARCHAR,      author_name VARCHAR,      borrow_count integer NOT NULL,      last_borrowed timestamp without time zone,      created_at timestamp without time zone NOT NULL  );  

and we would like to extract the one that was most borrowed (according to borrow_count) and the one that one that was least borrowed (according to borrow_count again). In both cases we would like to break ties.

Tie break:

  • For most borrowed we would like to break tie in favor of the most recently borrowed one
  • For least borrowed we select the least recently borrowed one (with NULL values winning the tie break) (optionally we can break this NULL ties with created_at in favor of oldest created_at, but this is very optional)

I could not come up with a decent solution beside combining two separate queries for min and max that would both order by and limit by 1. Can we do something better ?

The best method in order to perfect one's coding skills?

Posted: 17 Feb 2022 08:19 AM PST

I started coding about 3 months ago, and completely love it. I admire and aspire to be like the cool-tech guy that fixes problems and make jaw-dropping programs or apps. However I feel stuck whilst learning about the syntax of the language (like python and c sharp which I'm currently perfecting). The main focus of this question is whether completing tasks and projects with assistance such as coding/following the code of someone else on Youtube,helps me become a better programmer or is it just learning and understanding the syntax and then creating a project by myself and with my own knowledge.

Probs sounds like a dumb question, but my brain has been aching for an answer to this.

Why is the data in row truncated when importing CSV in MYSQL?

Posted: 17 Feb 2022 08:19 AM PST

I have a table in Mysql that looks like:

CREATE TABLE `overig`.`test`(  `ID` INT(10) AUTO_INCREMENT,  `Order_ID` DECIMAL(10) NOT NULL,  `Price_total` DECIMAL(12,2),  PRIMARY KEY (`ID`)  );  

I want to import the following CSV:

Order_ID;Price_total  145131343;118,35  145131349;79,35  

I load the CSV data into the MYSQL table:

LOAD DATA LOCAL INFILE 'test.csv' INTO TABLE `overig`.`test` FIELDS TERMINATED BY ';' ENCLOSED BY '"' LINES TERMINATED BY 'n' IGNORE 1 LINES  (`Order_ID`, @Price_total)  SET  `Price_total`  = 0 + REPLACE(@Price_total, ',', '.');  

The response:

Query OK, 2 rows affected, 1 warning (0.04 sec)  Records: 2  Deleted: 0  Skipped: 0  Warnings: 1    mysql> show warnings;  +-------+------+--------------------------------------------------+  | Level | Code | Message                                          |  +-------+------+--------------------------------------------------+  | Note  | 1265 | Data truncated for column 'Price_total' at row 2 |  +-------+------+--------------------------------------------------+  

Why do I get this warning? What's the difference between the value of row 2 and 3?

How to know what applications are available for the -a flag for the open command on mac command line

Posted: 17 Feb 2022 08:19 AM PST

I know that if I'm using the mac command line, I can open a file with the command

open file  

Furthermore, if I know the name of the application with which I want to open the file, I should be able to open it with

open -a "Application" file  

However, I can't figure out how to know what names I have available for "Applications," or how I might be able to add different applications to those that I can call in this way. Any pointers towards the right direction (or even what I could have done to figure this out on my own) would be so appreciated!

Using all 5, v3-8 TPUs provided by TRC Grant

Posted: 17 Feb 2022 08:18 AM PST

I have got access to use 5 on demand v3-8 TPUs and 5 on-demand v2-8 TPUs and 100 preemptable v2-8 TPUs. But I'm wondering, how can I use all 5 v3-8 TPUs at once and connect with the Google Cloud's VM instance.

Calculating Div and Mod using recursion

Posted: 17 Feb 2022 08:18 AM PST

I am fairly new to Python trying my best to wrap my head around this however it's a lot harder than I thought. I am attempting to write recursive functions in python that calculate div and mod. div takes two integers as input and keeps on subtracting the second from the first until the first number becomes less than the second number. The function keeps a track of how many times the second number is subtracted from the first and returns that number as the answer. mod also takes two integers as input and keeps on subtracting the second from the first until the first number becomes less than the second number. When the first number becomes less than the second, the value of the first number is the answer.

def lastDigit(x):   return mod(x,10)        def allButLast(x):   return div(x,10)  

Any help would be great thank you.

LABVIEW: How can I register on a callback from a CDLL

Posted: 17 Feb 2022 08:18 AM PST

The header file is the following:

#ifndef __EVTest_h_  #define __EVTest_h_  #include <stdint.h>  #include <stddef.h>  #define DLLIMPORT __declspec(dllimport)    // Typedefs ------------------------------------------------------------------    #pragma pack (push,1)    /// <summary>  ///   Callback called by Test  /// </summary>  /// <param name="B">  ///   Simple counter  /// </param>  typedef void (__cdecl *TEVCallback)(uint8_t B);    #pragma pack (pop)    // Functions ------------------------------------------------------------------    #ifdef __cplusplus  extern "C" {  

No comments:

Post a Comment