I have a question please. I am developing an online mall website. I have an orders table.. I have put the product_id as an attribute in order to know which product is ordered. In the customer’s purchase history page, I need to present all the orders purchased by the customer, including the product title…
MySQL query – join 4 tables together, with 3 tables using group by one column from each
Here are examples of the 4 tables I’m working with. And I’m trying to get outputs with php foreach something like this … This is the query I’ve come for one table… Answer You can cross join the items table with all available dates in the three other tables, and then the aggregati…
How to get the row index in SQLite3?
I have created a table that has a column of registration number as primary key. I have created row_id using row_number() that is ordered by the primary key. How can i search a registration number and get the row_id along with other information of that row? Answer If you have created the column row_id like: th…
How to join tables based on certain condition? SQL
There are three tables A,B,C Table A has columns [ID], [flag], [many other columns] Table B has columns [ID], [column subset of Table A] Table C has columns [ID], [same column subset as Table B (thus also a subset of Table A), however with different values] I want to join Table A & Table B if Flag = ̵…
SQL SERVER: Reset running total according to two conditions
I need to reset the running total when two conditions are met. See update below for clarification. Using SQL SERVER UPDATE 1: The Data: The data is partitioned by item number and ordered by the week of the year. Therefore, Item_Number = the item number. Cartons = the number of cartons sold that week per item …
Getting different results from LIKE query and stored procedure for (starts and ends with) search
I am trying to implement a stored procedure that gets the two parameters @startsWith and @endsWith and constructs this query string: @startswith + ‘%’ + @endsWith To search for entries of a single …
RECURSIVE QUERY – PARENT/CHILD
Say I have a table like so: id Parentid childid ——————————– 01 null 02 02 01 03 03 02 04 …
On delete Error: SQL Error: ORA-00933: SQL command not properly ended
I’m trying to delete a student record from the database using the below query. But I face this error. Error report – SQL Error: ORA-00933: SQL command not properly ended 00933. 00000 – “SQL command not properly ended” Answer Give this a shot to delete student record for which the…
How to count total number of patients in a certain age group
Hello I would like to ask how can I have the total number of patients in certain distinct age groups using queries? Answer In MySQL. In other DBMS similarly, but you must precise what you use.
How do I do NOT CONTAINS?
I’m having difficulties with a question on an assignment and writing the correct query. I’ve been at it for days, and it’s due soon. I’m trying to show all project numbers that do not contain employee id’s of 114 and 113 (the application designers). Looking at the table data, I c…