i just started my journey with SQL, and made some tables of Cyclists, and Cycling Teams. Cyclist’s table contains columns: ID, Name, Team (which is foreign key of TEAMS ID) Team’s table contains columns: ID, Name, Number of Cyclists I want to Count number of Cyclists in each team, by using count() function ( Or basically any function, i just
SQL: extract keys and values of a jsonb field as rows of two separate columns
In my postgresql DB I have the following query returning where json_field is of type JSONB. I am looking for a way to query all the keys and all the values from this json field, so that the output would be Is there a way to do it ? generalizing the question after it got the solution answer When I
How to push value selected from db as first if it is equal with value in other column?
I am doing autocomplete query system for cities and I have problem, that I want to prioritize main city of region from another results showed for exact phrase for ex. “%Trenc%”. If city and region are the same, I would like to place it as first result and then everything other. Trencin Trenc My idea is create another column in
How to create a trigger on table A that inserts/updates entity in table B?
I have tables TableAAA, TableBBB, TableCCC and TableCollected. The AAA/BBB/CCC tables have a DateTime column: I’d like to have a 1-1 trigger on each table that runs after inserting/updating. It should save the biggest DateTime from given table into the TableCollected table. So if TableAAA table contains 3 rows with dates 1980-01-01, 1990-01-01 and 2010-01-01 then in TableCollected I’d have
Find sum of hours for each date worked
I have a table of timesheet entries set up like this: id job_id employee_id hours_worked date_worked 1 1 111 8 2022-10-01 2 1 222 8 2022-10-01 3 1 222 8 2022-10-02 4 2 222 8 2022-10-03 5 2 111 8 2022-10-04 6 2 222 5 2022-10-05 7 3 111 8 2022-10-04 8 4 333 8 2022-10-07 9 4 111 3
SQL – Adding a % sign to NVL output/result set – pictures and code included
I am having trouble adding a percent sign to the output of the NVL() function. If you look in the desired output picture you will see that the commission needs to have a % added to it. I’ve tried various things but have been unable to get it to output correctly. I have tried concatenating a percent sign but that
I’m trying to insert rows into a database using executemany but rows not showing in database after executing code
Answer When I ran your code, I was able to query the database. It correctly inserted the items.
SQL Query to find top item of each group and display details from other tables
I am looking for a query to be able to identify the top-selling items (quantity) per location and to display details about that item and store. My tables are currently organized as such: Stores StoreID Location StoreName 1 San Diego Ralph’s 2 San Francisco Ralph’s 3 Sacramento Ralph’s Products ProductID Name Category 1 Milk Food 2 Eggs Food 3 Reese’s
SQL: difference between where in main body vs join clause
I’m wondering why does the following queries give me a slightly different dataset: So I just moved BETWEEN clause to the main body, logically, it does not matter where to apply it, but the result says it matters. Any suggestions? Thanks! UPD: tried on MySQL 5.6 Answer Maybe it’s hard to answer this question without some images! but I try.
Insert into SQL database from React front end
Im trying to insert some data into a SQL table but Im getting nothing from the front or back end I have tried console.log at various intervals but I cant seem to get data from either side. For reference I have table called products with three columns id, name, image Im trying to insert both name and image with a