154k views
0 votes
Write a query to display the invoice number, line numbers, product SKUs, product descriptions, and brand ID for sales of sealer and top coat products of the same brand on the same invoice. Sort the results by invoice number in ascending order, first line number in ascending order, and then by second line number in descending order

2 Answers

5 votes

Final answer:

To display the invoice number, line numbers, product SKUs, product descriptions, and brand ID for sales of sealer and top coat products of the same brand on the same invoice, you can use a SQL query with multiple joins and sorting conditions.

Step-by-step explanation:

To display the invoice number, line numbers, product SKUs, product descriptions, and brand ID for sales of sealer and top coat products of the same brand on the same invoice, you can use SQL query with multiple joins and sorting conditions. Here's an example:

SELECT i.invoice_number, l1.line_number, l1.product_sku, l1.product_description, l1.brand_id
FROM invoices i
JOIN lines l1 ON i.invoice_number = l1.invoice_number
JOIN lines l2 ON i.invoice_number = l2.invoice_number AND l1.brand_id = l2.brand_id
WHERE l1.product_description LIKE '%sealer%' AND l2.product_description LIKE '%top coat%'
ORDER BY i.invoice_number ASC, l1.line_number ASC, l2.line_number DESC;

This query assumes that the tables for invoices are named 'invoices' and the tables for lines are named 'lines'. Modify the table names and column names according to your database schema.

4 votes

Answer:

See explaination

Step-by-step explanation:

$query = "select * from LGINVOICE";

$result = mysql_query($query);

while($row=mysql_fetch_array($result)){

$inv = $row["INV_NUM"];

$query = "select * from LINE_Num where INV_NUM=$inv";

$result1 = mysql_query($query);

while($row1 = mysql_fetch_array($result1){

$sum+=$row1[PROD_SKU];

}

$query = "insert into SEALER(INV_NUM,BRAND_ID) values($inv,$sum)";

mysql_query($query);

}

User TheGwa
by
6.4k points